вот код( питон 3):
Код: Выделить всё
def plus_one(digits):
if digits==[9]:
digits=[1,0]
return digits
else:
if digits[-1]==9:
digits[-1]=0
digits[-2]=digits[-2]+1
while True:
if digits[0] > 9:
digits[0] = 1
digits.append(0)
return digits
else:
for digit in digits:
if digit>9:
digits[digits.index(digit) - 1] = digits[digits.index(digit)-1]+ 1
digits[digits.index(digit)] = 0
else:
return digits
print(plus_one([9,9,9]))
мой код возвращает [9,10,0] вместо [1,0,0,0], но отлично работает для [9,9], то есть возвращает [1,0,0]
Подробнее здесь: https://stackoverflow.com/questions/793 ... ot-working
Мобильная версия