class Solution:
def multiply(self, num1: str, num2: str) -> str:
if num1 == '0' or num2 == '0':
return '0'
num1 = num1[::-1]
num2 = num2[::-1]
result = [0] * (len(num1) + len(num2))
for index1 , i1 in enumerate(num1):
# n1 = int(i1)
for index2 , i2 in enumerate(num2):
# n2 = int(i2)
sum = result[index1 + index2] + int(i1)*int(i2)
result[index1 + index2] = sum % 10
result[index1 + index2 + 1] += sum // 10
res = ''.join([ str(x) for x in result ])[::-1].lstrip('0')
# res = ''.join(res)
# res = res[::-1]
# res = res.lstrip('0')
return res
转载:https://blog.csdn.net/leileii/article/details/101546823
查看评论