43. Multiply Strings
题目描述
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.
Note:
- The length of both num1 and num2 is < 110.
- Both num1 and num2 contains only digits 0-9.
- Both num1 and num2 does not contain any leading zero.
- You must not use any built-in BigInteger library or convert the inputs to integer directly.
题目大意
大数乘法。
解题思路
模拟手算的过程,以数组
pos
储存结果,第一个字符串的第i
位 和 第二个字符串的第j
位相乘,一定是结果的的第i + j
位,那么对当前结果进行取余就是 进位,即i + j + 1
位。
最后剔除掉数组pos
内所有前置位的0
。
代码
|
|