A non-negative whole number is written out digit by digit in the array digits: digits[0] is the most significant digit and the last element is the ones digit. The number has no leading zeros, except for the number 0 itself, which is written [0].
Add one to the number and return its digits in the same form.
407 + 1 = 408: only the last digit changes.
299 + 1 = 300. Each 9 becomes 0 and passes a carry to the left.
99 + 1 = 100. The carry runs off the front, so the answer is one digit longer.
Constraints
1 <= digits.length <= 1000 <= digits[i] <= 9digits has no leading zeros, unless it is exactly [0].Work from the last digit, like adding by hand. A digit below 9 just goes up by one and you're done. A 9 turns into 0 and passes a carry to the left.