# Question

Formatted question description: https://leetcode.ca/all/66.html

Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.

You may assume the integer does not contain any leading zero, except the number 0 itself.

Example 1:

Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.

Example 2:

Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.

@tag-array


# Algorithm

If the number at the end is 9, then there will be a carry problem, and if the number in the previous digit is still 9, you need to continue to advance. The specific algorithm is as follows:

1. first judge whether the last digit is 9, if not, add one directly to return,
2. if it is, then assign 0 to the digit, and then continue to check the previous digit, the same method, until the first digit is checked.
3. If the first digit was originally 9, a new digit will be generated after adding one, then the last thing to do is to check whether the first digit after the calculation is 0, if it is, add a 1 to the top.

Java