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.
Example 1
Input: digits = [1,2,9]
Output: [1,3,0]
Explanation: 129 + 1 = 130. The last digit 9 becomes 0 and carries 1 into the 2, which becomes 3.
Example 2
Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: 123 + 1 = 124. The last digit simply goes from 3 to 4.
Example 3
Input: digits = [9]
Output: [1,0]
Explanation: 9 + 1 = 10. The carry runs past the first digit, so a new leading 1 is added.
Add one at the least-significant digit and let the carry ripple left. Any digit below 9 absorbs the +1 and we're done; a 9 rolls over to 0 and passes the carry on. If every digit was 9, prepend a leading 1.
Run checks all cases above. Submit evaluates all test cases.