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
andnum2
is < 110. - Both
num1
andnum2
contains only digits0-9
. - Both
num1
andnum2
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