We’re preparing your current view and syncing the latest data.
You are given a non-empty array of digits representing a non-negative integer. Increment one to the integer.
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit.
You may assume the integer does not contain any leading zero, except the number 0 itself.
An array of digits, each an integer between 0 and 9.
Return the resulting array of digits after adding one to the integer.
1 <= digits.length <= 100 0 <= digits[i] <= 9 The integer represented by digits does not have leading zeros except for the number 0 itself.
Example 1
Input
[1,2,3]
Output
[1,2,4]
Explanation
The array represents the integer 123. Adding one results in 124.
Example 2
Input
[9,9,9]
Output
[1,0,0,0]
Explanation
The array represents the integer 999. Adding one results in 1000.