3 ms C++ solution


  • 0
    D
        string complexNumberMultiply(string c1, string c2) {
            if(c1.length() == 0|| c2.length() == 0)
                return "";
            string result = "";
            int a,b,c,d;
            string::size_type sz;
            sz = 0;
            a = stoi(c1,&sz);
            
            b = stoi(c1.substr(sz+1),NULL);
            sz =0;
            
            c = stoi(c2,&sz);
            d = stoi(c2.substr(sz+1),NULL);
            int A = a*c - b*d;
            int B = a*d + c*b;
            result += to_string(A);
             result+="+";
            result += to_string(B);  
            result+="i";
          return result;  
        }
    

Log in to reply
 

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