Problem
You get a non-negative integer as an array of digits, digits. The array starts with the leftmost digit of the integer and ends with the rightmost digit.
The integer has no zeros at the start, except when the integer is 0.
Add 1 to the integer. Return the result as an array of digits in the same form.
Example 1
- Input:
- digits = [4,0,7]
- Output:
- [4,0,8]
- Explanation:
- The array holds the integer 407, and
407 + 1is 408.
Example 2
- Input:
- digits = [2,9,9]
- Output:
- [3,0,0]
- Explanation:
- The integer is 299, and
299 + 1is 300. Each 9 at the end becomes 0, and the 2 becomes 3.
Example 3
- Input:
- digits = [9,9]
- Output:
- [1,0,0]
- Explanation:
- The result 100 has one more digit than 99.
Constraints
- 1 <= digits.length <= 100
- 0 <= digits[i] <= 9
- digits has no zeros at the start, except for the integer 0.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Plus One Linked List
Coding
- Alert Using Same Key-Card Three or More Times in a One Hour Period
Coding
- All O`one Data Structure
Coding · Design · Doubly-Linked List · Hash Table
- Allow One Function Call
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 66. Plus One
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source