Add Two Numeric Strings with Carry
Problem statement
You are given two strings, a and b, representing nonnegative decimal integers. Return their decimal sum as a string.
Perform digit-by-digit addition with carry; the inputs may be too large for fixed-width numeric types.
Function
addNumericStrings(a: String, b: String) → StringExamples
Example 1
a = "999"b = "1"return = "1000"Adding the final digits produces a carry through all three nines.
Example 2
a = "123"b = "789"return = "912"Right-to-left addition gives units 2, tens 1, and hundreds 9.
Constraints
1 <= a.length,b.length <= 10000- Both inputs contain only decimal digits.
- Neither input has a leading zero unless it equals
"0".