12345678910111213141516171819 |
- from typing import List
- def plusOne(digits: List[int]) -> List[int]:
- i = len(digits) - 1
- digits[i] = digits[i] + 1
- while i > 0:
- if digits[i] == 10:
- digits[i - 1] = digits[i - 1] + 1
- digits[i] = 0
- i -= 1
- else:
- break
- if digits[0] == 10:
- digits[0] = 0
- digits.insert(0, 1)
- return digits
- print(plusOne([9,9,9,0]))
|