Multiply Strings
MediumMath & Geometry
You are given two non-negative integers num1 and num2 written as decimal strings. Return their product, also as a decimal string.
The result must not have leading zeros (a product of zero is "0").
Do the arithmetic yourself: do not convert the whole input strings to integers with int() or use any big-integer library. Working with individual digits is fine.
Example 1
- Input:
- num1 = "25", num2 = "804"
- Output:
- "20100"
- Explanation
- 25 x 804 = 20100. Note the result has zeros in the middle and at the end that must be kept, but no leading zeros.
Example 2
- Input:
- num1 = "99", num2 = "99"
- Output:
- "9801"
- Explanation
- 99 x 99 = 9801. Each partial product overflows a single digit and carries into the next column.
Example 3
- Input:
- num1 = "0", num2 = "4521"
- Output:
- "0"
- Explanation
- The product is zero, which is written as the single character
"0", not"0000".
Constraints
1 <= num1.length, num2.length <= 200num1andnum2consist of digits only- Neither input has a leading zero, except the number
0itself