Simple Java Solution

  • 0
    public String complexNumberMultiply(String a, String b) {
             String[] aarr = a.split("\\+");
             String[] barr = b.split("\\+");
        int a1 = Integer.parseInt(aarr[0]);
        int b1 = Integer.parseInt(aarr[1].replace("i",""));
        int a2 = Integer.parseInt(barr[0]);
        int b2 = Integer.parseInt(barr[1].replace("i",""));
            return a1*a2-b1*b2+"+"+Integer.toString(a1*b2+b1*a2)+"i";

Log in to reply

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