Java elegant solution


  • 0
    K
        public String complexNumberMultiply(String a, String b) {
            String[] as=a.split("[+]");
            String[] bs=b.split("[+]");
            
            int a1=Integer.parseInt(as[0]);
            int ai=Integer.parseInt(as[1].substring(0,as[1].length()-1));
            
            int b1=Integer.parseInt(bs[0]);
            int bi=Integer.parseInt(bs[1].substring(0,bs[1].length()-1));
            
            int c1=a1*b1-ai*bi;
            int ci=ai*b1+bi*a1;
            
            return ""+c1+"+"+ci+"i";
        }
    

Log in to reply
 

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