An odometer stores a non-negative whole number as a list of its decimal digits, most significant first, with no leading zeros (zero is [0]).
Write add_one(digits) -> list that returns the digits of the number plus one, in the same format.
add_one([1, 2, 3]) # [1, 2, 4]
add_one([4, 9, 9]) # [5, 0, 0]
add_one([9, 9]) # [1, 0, 0]
add_one([0]) # [1]
1 <= len(digits) <= 10^5, each digit is in0..9.- The number can be far too long for a machine integer, so work with the digits directly.
- ⭐ Bonus: a speed test with 100,000 digits earns a star in O(n).
Show hint
think about how you add one by hand: which digits can actually change, and when do you get to stop?