1. 程式人生 > >Leetcode 43. Multiply Strings

Leetcode 43. Multiply Strings

cnblogs lee bject blog code elf def sel type

class Solution(object):
    def multiply(self, num1, num2):
        """
        :type num1: str
        :type num2: str
        :rtype: str
        """
        
        n1 = len(num1)
        n2 = len(num2)
        
        num1 = num1[::-1]
        num2 = num2[::-1]
        
        prod = 0
        
for i in range(n1): for j in range(n2): cur = int(num1[i])*int(num2[j]) prod += cur*10**(i+j) return str(prod)

Leetcode 43. Multiply Strings