1. Code
class Solution:
def complexNumberMultiply(self, a: str, b: str) -> str:
a, b = a[:-1], b[:-1] # Remove the 'i' at the back of a and b
a_real, a_imag = map(int, a.split('+')) # Distinguish a real number from a imaginary number
b_real, b_imag = map(int, b.split('+'))
return str(a_real*b_real + -1*a_imag*b_imag) + "+" + str(a_real*b_imag + b_real*a_imag) + "i"
2. Result
Runtime : 12 ms(100.00%), Memory usage : 14.1 MB(93.47%)
(Runtime can be different by a system even if it is a same code.)