Given a non-empty array of decimal 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.
Example 1:
1 | Input: digits = [1,2,3] |
Example 2:
1 | Input: digits = [4,3,2,1] |
Example 3:
1 | Input: digits = [0] |
給一個1-9數字陣列[8,8],實作十進位器,從右邊開始,當遇到9以下加1,進位要考慮2個情況,一個是陣列內9加1要進到左邊一位[8,9],另一個是超出陣列的進位,像[9,9]再加1 [1,0,0]。
Java
1 | class Solution { |
如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)