-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ66
More file actions
34 lines (33 loc) · 859 Bytes
/
Q66
File metadata and controls
34 lines (33 loc) · 859 Bytes
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
26
27
28
29
30
31
32
33
34
class Solution: #
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
i,g=0,1
lReturn = []
for i in range(len(digits)):
lReturn.append(int((digits[-1-i]+g)%10))
if (digits[-1-i]+g)>9:
g=1
else:
g=0
if g==1:
lReturn.append(1)
return lReturn[::-1]
class Solution:#same
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
i,g=0,1
for i in range(len(digits)):
digits[-1-i]=int((digits[-1-i]+g)%10)
if digits[-1-i]==0 and g==1:
g=1
else:
g=0
if g==1 and digits[0]==0:
digits.insert(0,1)
return digits