
Plus One (easy)
Problem Statement
You are given a digits array, where digits[i] is between 0 to 9. It is given that when you combine all elements of the digits array in left to right order, it forms the large integer.
Add 1 to large integer and return the array containing the digits of the resultant large integer.
Examples
-
Example 1:
- Input:
[1, 2, 3] - Expected Output:
[1, 2, 4] - Justification: The number 123 is incremented to 124. No carry over beyond the last digit.
- Input:
-
Example 2:
- Input:
[4, 9, 9, 9] - Expected Output:
[5, 0, 0, 0] - Justification: Incrementing 4999 results in a carry over at each digit, leading to 5000.
- Input:
-
Example 3:
- Input:
[9, 8, 7, 6, 8, 9, 9, 9] - Expected Output:
[9, 8, 7, 6, 9, 0, 0, 0] - Justification: Incrementing the last three digits of 98768999 by 1 results in a carry that changes these digits to 0 and increases the 5th digit by 1, resulting in 98769000.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory