Plus One

A non-negative integer is stored as an array of its decimal digits, most significant first: [1, 2, 3] is 123. Add one to the number and return its digits the same way.

The number has no leading zeros, except the number 0 itself, which is [0].

Constraints

  • 1 ≤ length of digits ≤ 100
  • 0 ≤ digits[i] ≤ 9

Example 1

Input
digits = [1,2,3]
Output
[1,2,4]
Why:

123 + 1 = 124.

Example 2

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

The two 9s turn into 0s and carry.

Example 3

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

9 + 1 = 10 needs one more digit.

Hints

    Was this a good challenge?

    Solved by
    0
    Submissions
    0
    Accepted
    –