The damn elegant Python 2-liners!

  • 0

    It' very elegant in python. Also, it's very easy to understand if you know the map function!

    class Solution(object):
        def complexNumberMultiply(self, a, b):
            :type a: str
            :type b: str
            :rtype: str
            a_r, a_i, b_r, b_i = map(lambda x: int(x.strip('i')), a.split('+') + b.split('+'))
            return str(a_r * b_r - a_i * b_i) + "+" + str(a_r * b_i + a_i * b_r) + "i"

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.