Medium
Quiz
#537 Complex Number Multiplication
APPROACH
A complex number is encoded as the string "real+imaginaryi" where:
- real is an integer in [-100, 100] representing the real component.
- imaginary is an integer in [-100, 100] representing the imaginary component.
- i2 == -1.
Given two such encoded strings num1 and num2, compute their product and return the result in the same string format.
Example 1:
Input: num1 = "1+1i", num2 = "1+1i"
Output: "0+2i"
Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i.
Example 2:
Input: num1 = "1+-1i", num2 = "1+-1i"
Output: "0+-2i"
Explanation: (1 - i) * (1 - i) = 1 + i2 - 2 * i = -2i, and you need convert it to the form of 0+-2i.
1 of 4
1:00
What is the optimal approach for this problem?