-
Notifications
You must be signed in to change notification settings - Fork 19
/
answer.py
25 lines (23 loc) · 828 Bytes
/
answer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
#-------------------------------------------------------------------------------
class Solution:
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
# range to -1, because of the uninclusive lower bound
for i in range(len(digits)-1, -1, -1):
digits[i] += 1
if digits[i] > 9:
# if it is 9, set to zero and repeat on left element
digits[i] = 0
# if it is leftmost, insert a 1 in the head
if i == 0:
digits.insert(0, 1)
# break if add has no complications
else:
break;
return digits
#-------------------------------------------------------------------------------
# Testing