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.
博客围绕 LeetCode 43 题,即两个值为整数的字符串相乘并以字符串表示乘积展开。给出的思路是先将两个字符串转化为整型相乘,再把乘积转化为字符串,还提及用 Python 代码实现。
1002

被折叠的 条评论
为什么被折叠?



