Description
Given a large integer represented as an integer array digits, increment the number by one and return the resulting array of digits.
Examples
Input:
digits = [9,9,9]Output:
[1,0,0,0]Explanation:
999 + 1 = 1000.
Input:
digits = [5,9,9]Output:
[6,0,0]Explanation:
599 + 1 = 600. The carry propagates through the trailing 9s, turning them to 0s and incrementing the first non-9 digit (5 becomes 6).
Input:
digits = [7]Output:
[8]Explanation:
7 + 1 = 8. A single digit that does not cause a carry, so the digit is simply incremented.
Constraints
- •
1 ≤ digits.length ≤ 100 - •
0 ≤ digits[i] ≤ 9