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.
解法1:
按位相乘,注意把中间结果要存储在一个res[length1 + length2]的数组里。
然后从后往前扫描,比较容易错的是对应的res的数组的位置。要特别注意一下。
C++
Java
精简很多的code的写法:
|
|