dsa · easy

Add Strings

Two non-negative integers arrive as decimal digit strings num1 and num2 (no extra leading zeros except the number 0 itself). Return their sum as a decimal digit string. The strings can be longer than a machine integer; add them as digits, not by parsing the whole value.

Arguments

Example

num1 = "11", num2 = "123". Align from the right: 1+3 = 4, 1+2 = 3, leftover 1"134".

num1 = "0", num2 = "0""0".

Constraints

1 <= num1.length, num2.length <= 4*10^4 num1 and num2 contain only digits and have no leading zeros except 0 itself. Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
'11'
'123'

Expected:
134

Example 2

Input:
'456'
'77'

Expected:
533

Example 3

Input:
'0'
'0'

Expected:
0

Open in the Dojo editor