The Pythonic way to do this. 5 lines code. Is this cheating?

  • -2

    I hope this isn't cheating:

    def multiply(self, num1, num2):
        :type num1: str
        :type num2: str
        :rtype: str
        result = 0
        for i1, d1 in enumerate(num1[::-1]):
            for i2, d2 in enumerate(num2[::-1]):
                result += int(d1)*(10**i1) * int(d2)*(10**i2)
        return str(result)

  • 0

    Can't work when result is too big.

  • 0

    Not valid because the intermediate result is stored as integer.

Log in to reply

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