32. Plus One

Increment the integer represented by digits in the array by one.
Example 1
Input: digits = [4,3,2,1]
Output: [4,3,2,2]
Explanation: Add 1 to the last digit: 1->2, no carries -> [4,3,2,2].
Example 2
Input: digits = [9,9,9]
Output: [1,0,0,0]
Explanation: All digits are 9: after adding 1 we get a carry through all digits -> [1,0,0,0].
Example 3
Input: digits = [1,2,3]
Output: [1,2,4]
Explanation: Add 1 to the last digit: [1,2,3] -> [1,2,4].
arraysmedium
JavaScript
Loading...
Line 1, Char 1