码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 43. Multiply Strings

时间:2017-05-15 10:06:00      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:rod   elf   solution   sel   object   return   string   turn   bsp   

 

 

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

标签:rod   elf   solution   sel   object   return   string   turn   bsp   

原文地址:http://www.cnblogs.com/lettuan/p/6854840.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!