Add One to Digits

When a number is very large, it can be stored as an array of digits instead of a regular int. The function plus_one receives a list digits, with the most significant digit first. Add 1 to this number and return the result in the same digit-list format. Remember the carry case, such as 9 becoming [1, 0].

Примеры

Ввод
[[1, 2, 3]]
Вывод
[1, 2, 4]
Ввод
[[4, 3, 2, 1]]
Вывод
[4, 3, 2, 2]
Ввод
[[9]]
Вывод
[1, 0]

Нужно реализовать

def plus_one(digits):

Теги

arraymath
PostgreSQLv16

Koodin suorituksen tulos näkyy tässä

Visible tests
1
Input
[1,2,3]
Expected[1,2,4]
2
Input
[4,3,2,1]
Expected[4,3,2,2]
3
Input
[9]
Expected[1,0]
4
Input
[9,9,9]
Expected[1,0,0,0]
5
Input
[0]
Expected[1]
6
Input
[1,2,3,1,2]
Expected[1,2,3,1,3]
Focus radio
Paused · SomaFM · Fluid