43. Multiply Strings

class Solution(object):
    def multiply(self, num1, num2):
        """
        :type num1: str
        :type num2: str
        :rtype: str
        """
        num1,num2=num1[::-1],num2[::-1]
        res=[0]*(len(num1)+len(num2))
        for i in xrange(len(num1)):
            for j in xrange(len(num2)):
                res[i+j]+=int(num1[i])*int(num2[j])
                res[i+j+1]+=res[i+j]/10
                res[i+j]=res[i+j]%10
        l=len(res)-1
        while l>0 and res[l]==0:
            l-=1 
        return ''.join(map(str,res[l::-1]))
                

你可能感兴趣的:(43. Multiply Strings)