You are given a non-empty array of decimal digits that encodes a non-negative whole number. Add one to that number. The first array entry holds the highest-place digit, and every entry stores exactly one digit. Apart from the value 0 itself, the represented number will not begin with zero.
A non-empty array digits that encodes a non-negative integer.
Return an array encoding the value represented by the input after adding one.
Input:
3 1 2 9
Output:
1 3 0
[2,5,6]
[2,5,7]
This digit array corresponds to 256, so adding one produces 257.
digits = [2, 5, 6][2,5, 7]
We start with the digit array [2, 5, 6].
[7,1,0,8]
[7,1,0,9]
The digits form 7108, and its next integer is 7109.
100 elements.digits[i] lies within [0, 9].Input: [8, 9, 9]
Output: [9, 0, 0]
digits = [2, 5, 6][2,5, 7]
We start with the digit array [2, 5, 6].