Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.
就是两个值为整数的字符串相乘,将他们的乘积也用字符串表示。
思路
先将两个数分别转化为整型,然后相乘,再将乘积转化为字符串
class Solution:
def strToInt(self, s):
res = 0
l = len(s)
pos = 0
while pos < l:
iP = (int)(s[pos])
res+=(iP)*pow(10,l-pos-1)
pos+=1
return res
def multiply(self, num1: str, num2: str) -> str:
i1 = self.strToInt(num1)
i2 = self.strToInt(num2)
return str(i1*i2)
THE END.