Skip to content
BASA DSA

Plus One

EasyMath & Geometry

Add one to a nonnegative integer represented by most-significant-first decimal digits. Return the resulting digit array.

Example 1

Input
digits = [1,9,9]
Output
[2,0,0]

Explanation

A carry turns both final 9 digits to zero and increments 1 to 2.

Example 2

Input
digits = [9,9]
Output
[1,0,0]

Explanation

Both digits overflow, requiring a new leading 1.

Example 3

Input
digits = [0]
Output
[1]

Explanation

The single zero increments to one.

Constraints

  • 1 <= number of digits <= 100
  • Digits are 0..9
  • No leading zeros except zero itself

Function contractplusOneArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…