|
| 1 | +// Problem description |
| 2 | +/* You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. |
| 3 | + |
| 4 | +Increment the large integer by one and return the resulting array of digits. |
| 5 | + |
| 6 | +Example 1: |
| 7 | + |
| 8 | +Input: digits = [1,2,3] |
| 9 | +Output: [1,2,4] |
| 10 | +Explanation: The array represents the integer 123. |
| 11 | +Incrementing by one gives 123 + 1 = 124. |
| 12 | +Thus, the result should be [1,2,4]. |
| 13 | +Example 2: |
| 14 | + |
| 15 | +Input: digits = [4,3,2,1] |
| 16 | +Output: [4,3,2,2] |
| 17 | +Explanation: The array represents the integer 4321. |
| 18 | +Incrementing by one gives 4321 + 1 = 4322. |
| 19 | +Thus, the result should be [4,3,2,2]. |
| 20 | +Example 3: |
| 21 | + |
| 22 | +Input: digits = [9] |
| 23 | +Output: [1,0] |
| 24 | +Explanation: The array represents the integer 9. |
| 25 | +Incrementing by one gives 9 + 1 = 10. |
| 26 | +Thus, the result should be [1,0]. */ |
| 27 | + |
| 28 | +// solution |
1 | 29 | let digits = [4, 3, 2, 1];
|
2 | 30 |
|
3 | 31 | let plusOne = function (digits) {
|
|
0 commit comments