7-line Python Solution


  • -1
    M
    class Solution(object):
        def multiply(self, num1, num2):
            """
            :type num1: str
            :type num2: str
            :rtype: str
            """
            l1 = map(int, num1)[::-1]
            l2 = map(int, num2)[::-1]
            sum = 0
            for i, m in enumerate(l1):
                for j, n in enumerate(l2):
                    sum += m * n * 10 ** (i + j)
            return str(sum)

  • 0
    D

    You relied on Python's BigInt to store infinitely long integer sum, which is forbidden.


Log in to reply
 

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