Description
You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits.
Examples
Input:
digits = [1,2,3]Output:
[1,2,4]Explanation:
The array represents the integer 123. Incrementing by one gives 124.
Input:
digits = [9,9,9]Output:
[1,0,0,0]Explanation:
The array represents the integer 999. Incrementing by one gives 1000.
Input:
digits = [1,9,9]Output:
[2,0,0]Explanation:
The array represents the integer 199. Incrementing by one gives 200. Adding 1 to the last digit (9) creates a carry that propagates through multiple digits, turning both 9's into 0's and incrementing the first digit from 1 to 2.
Constraints
- •
1 ≤ digits.length ≤ 100 - •
0 ≤ digits[i] ≤ 9 - •
digits does not contain any leading 0's.