题目:
给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式。
示例1:
输入: num1 = "2", num2 = "3"
输出: "6"
示例2:
输入: num1 = "123", num2 = "456"
输出: "56088"
算法实现:
class Solution:
def multiply(self, num1: str, num2: str) -> str:
count1 = len(num1) - 1
result1 = 0
count2 = len(num2) - 1
result2 = 0
for each1 in num1:
result1 += int(each1) * (10 ** count1)
count1 -= 1
for each2 in num2:
result2 += int(each2) * (10 ** count2)
count2 -= 1
return str(result1 * result2)
s = Solution()
print(s.multiply("123","456"))