Skip to content

Plus One

EasyBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.

A large non-negative integer is stored as a list of digits, most significant first, with no leading zeros (except the number 0 itself). Add one to it and return the new list of digits.

digits = [1, 2, 3]  →  [1, 2, 4]
digits = [1, 9, 9]  →  [2, 0, 0]
digits = [9, 9, 9]  →  [1, 0, 0, 0]

Constraints

  • 1 <= digits.length <= 100
  • 0 <= digits[i] <= 9
  • digits has no leading zeros, except for the number 0 itself.