leetcode43 Multiply Strings

来源:互联网 发布:kismet windows 编辑:程序博客网 时间:2024/06/10 15:09

Given two numbers represented as strings, return multiplication of the numbers as a string.
Note:
The numbers can be arbitrarily large and are non-negative.
Converting the input string to integer is NOT allowed.
You should NOT use internal library such as BigInteger.

小学乘法

class Solution(object):    def multiply(self, num1, num2):        """        :type num1: str        :type num2: str        :rtype: str        """        n1=list(num1)#;n1.reverse()        n2=list(num2)#;n2.reverse()        ret=0        for i in range(len(n1)):            sum_=0            for j in range(len(n2)):                sum_=sum_+int(n2[len(n2)-1-j])*int(n1[len(n1)-1-i])*(10**j)            ret=ret+sum_*(10**i)        return str(ret)
0 0
原创粉丝点击