首页 > 学院 > 开发设计 > 正文

LeetCode(43) Multiply Strings

2019-11-08 02:04:26
字体:
来源:转载
供稿:网友

Description

Given two non-negative integers num1 and num2 rePResented as strings, return the product of num1 and num2.

Note:

The length of both num1 and num2 is < 110.Both num1 and num2 contains only digits 0-9.Both num1 and num2 does not contain any leading zero.You must not use any built-in BigInteger library or convert the inputs to integer directly.

Workflow

把字符串转换为整形数据,然后相乘

Code

class Solution(object): def multiply(self, num1, num2): """ :type num1: str :type num2: str :rtype: str """ num1=self.str2int(num1) num2=self.str2int(num2) return str(num1*num2) def str2int(self,str): num=0 for i in range(len(str)): num+=int(str[i])*(10**(len(str)-i-1)) return num
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表