@@ -0,0 +1,1536 @@
+package math;%0A%0Apublic class Q537ComplexNumberMultiplication %7B%0A%0A    //Difficulty: medium%0A    //TAG: string%0A    //TAG: math%0A%0A    /**%0A     * 537. Complex Number Multiplication%0A     * Given two strings representing two complex numbers.%0A     *%0A     * You need to return a string representing their multiplication. Note i2 = -1 according to the definition.%0A     *%0A     * Example 1:%0A     * Input: %221+1i%22, %221+1i%22%0A     * Output: %220+2i%22%0A     * Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.%0A     * Example 2:%0A     * Input: %221+-1i%22, %221+-1i%22%0A     * Output: %220+-2i%22%0A     * Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.%0A     * Note:%0A     *%0A     * The input strings will not have extra blank.%0A     * The input strings will be given in the form of a+bi, where the integer a and b will both belong to the range of %5B-100, 100%5D. And the output should be also in this form.%0A     */%0A%0A    /*%0A    Solution:%0A%0A    Time: O(a + b)%0A    Space: O(1)%0A     */%0A%0A    public String complexNumberMultiply(String a, String b) %7B%0A        int%5B%5D arr1 = buildArr(a), arr2 = buildArr(b);%0A        int i = arr1%5B0%5D * arr2%5B0%5D, j = arr1%5B0%5D * arr2%5B1%5D + arr1%5B1%5D * arr2%5B0%5D, k = arr1%5B1%5D * arr2%5B1%5D;%0A        return %22%22 + (i - k) + %22+%22 + j + %22i%22;%0A    %7D%0A%0A    private int%5B%5D buildArr(String str) %7B%0A        String%5B%5D strs = str.split(%22%5C%5C+%22);%0A        return new int%5B%5D%7BInteger.parseInt(strs%5B0%5D),%0A                        Integer.parseInt(strs%5B1%5D.substring(0, strs%5B1%5D.length() - 1))%7D;%0A    %7D%0A%0A%7D%0A

537. Complex Number Multiplication