Leetcode 43. Multiply Strings

 

 

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)

 

posted @ 2017-05-15 08:51  lettuan  阅读(101)  评论(0编辑  收藏  举报