dsa · medium
Multiply Strings
num1 and num2 are non-negative integers given as decimal strings (digits 0-9, no extra leading zeros except the number "0" itself). Return their product as a decimal string.
Arguments
num1— first non-negative integer as a decimal digit stringnum2— second non-negative integer as a decimal digit string
Do not turn the whole strings into machine integers in one shot — the values may be longer than a 64-bit word. Multiply digit by digit.
Example
num1 = "2", num2 = "3" → "6".
num1 = "123", num2 = "456": 123×400 = 49200, 123×50 = 6150, 123×6 = 738, and 49200+6150+738 = 56088.
num1 = "0", num2 = "123" → "0".
Constraints
1 <= num1.length, num2.length <= 200 num1 and num2 consist of digits 0-9 Neither string has a leading zero unless it is exactly 0 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: "2" "3" Expected: 6
Example 2
Input: "123" "456" Expected: 56088
Example 3
Input: "0" "123" Expected: 0