Leetcode 43. Multiply Strings

Posted lettuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)

 

以上是关于Leetcode 43. Multiply Strings的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 43. Multiply Strings

Leetcode43. Multiply Strings

LeetCode 43. Multiply Strings

<LeetCode OJ> 43. Multiply Strings

LeetCode题意分析&解答43. Multiply Strings

LeetCode 43. Multiply Strings