3ms C++ solution


  • 0
        vector<int> getNums(string s)
        {
            int i=0;
            while(s[i]!='+') ++i;
            int x = stoi(s.substr(0, i));
            int y = stoi(s.substr(i+1, s.length()-1));
            return vector<int> ({x, y});
        }
        string complexNumberMultiply(string a, string b) {
            vector<int> A = getNums(a);
            vector<int> B = getNums(b);
            return to_string(A[0]*B[0] - A[1]*B[1]) + "+" + to_string(A[0]*B[1] + A[1]*B[0]) + "i";
        }
    

Log in to reply
 

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