Readable & Easy to Understand Java Solution


  • 0
    L

    public class Solution {
    public String complexNumberMultiply(String s, String t) {
    int index1 = s.indexOf('+');
    int index2 = t.indexOf('+');
    int index3 = s.indexOf('i');
    int index4 = t.indexOf('i');
    int a = Integer.parseInt(s.substring(0,index1));
    int b = Integer.parseInt(s.substring(index1+1,index3));
    int c = Integer.parseInt(t.substring(0,index2));
    int d = Integer.parseInt(t.substring(index2+1,index4));
    StringBuffer result = new StringBuffer();
    result.append(Integer.toString(ac-bd));
    result.append("+");
    result.append(Integer.toString(ad+bc));
    result.append("i");
    return result.toString();
    }
    }>! Spoiler


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.