Plus One
Add one to a nonnegative integer represented by most-significant-first decimal digits. Return the resulting digit array.
Example 1
digits = [1,9,9][2,0,0]Explanation
A carry turns both final 9 digits to zero and increments 1 to 2.
Example 2
digits = [9,9][1,0,0]Explanation
Both digits overflow, requiring a new leading 1.
Example 3
digits = [0][1]Explanation
The single zero increments to one.
Constraints
- 1 <= number of digits <= 100
- Digits are 0..9
- No leading zeros except zero itself
Function contract
plusOneArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 32 cases, on your device.
[1,9,9]