Plus One
Return the digits after adding one.
Examples
Input: [1,2,3]
Output: [1,2,4]
Input: [9,9,9]
Output: [1,0,0,0]
Hints
Start from the end of the array and increment the last digit by 1, handling carry-over if the digit becomes 10.
If after processing all digits there's still a carry, insert a 1 at the beginning of the array.
Optimize the solution to handle large arrays efficiently by avoiding unnecessary operations and minimizing space usage.
Related Problems
Plus One
Return the digits after adding one.