Leetcode 537 Solution

This article provides solution to leetcode question 537 (complex-number-multiplication)

https://leetcode.com/problems/complex-number-multiplication

Solution

class Solution:
    def complexNumberMultiply(self, a: str, b: str) -> str:
        ra, va = a.split("+")
        ra = int(ra)
        va = int(va[:-1])

        rb, vb = b.split("+")
        rb = int(rb)
        vb = int(vb[:-1])

        return "{}+{}i".format(ra * rb - va * vb, ra * vb + rb * va)