537. Complex Number Multiplication
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 72% Topics: Math, String, Simulation
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(1)
# Space: O(1)
class Solution(object):
def complexNumberMultiply(self, a, b):
"""
:type a: str
:type b: str
:rtype: str
"""
ra, ia = map(int, a[:-1].split('+'))
rb, ib = map(int, b[:-1].split('+'))
return '%d+%di' % (ra * rb - ia * ib, ra * ib + ia * rb)
Solution from kamyu104/LeetCode-Solutions · MIT