Skip to main content
Back to problems
Leetcode
Easy
Arrays
Math
Plus One

Increment a non-negative integer represented as an array of digits and return the updated digit array.

Acceptance 100%
Problem Statement

You are given a non-negative integer represented as an array of decimal digits, where the most significant digit comes first. Add one to the integer and return the resulting array of digits.

The returned array should not contain leading zeros unless the number itself is zero.

Input Format

  • A list of digits digits, where each element is an integer from 0 to 9.
  • The digits represent a non-negative integer in most-significant-digit first order.

Output Format

  • Return a new list of digits representing the value digits + 1.

Constraints

  • 1 <= digits.length
  • Each digits[i] is in the range [0, 9]
  • digits represents a valid non-negative integer without leading zeros, except possibly when the number is zero.
Examples
Sample cases returned by the problem API.

Example 1

Input

digits = [1,2,3]

Output

[1,2,4]

Explanation

123 + 1 = 124.

Example 2

Input

digits = [4,3,2,1]

Output

[4,3,2,2]

Explanation

4321 + 1 = 4322.

Show 1 more example

Example 3

Input

digits = [9]

Output

[1,0]

Explanation

9 + 1 = 10.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.