-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path66.py
39 lines (35 loc) · 907 Bytes
/
66.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def plusOne(digits):
length=len(digits)-1
if digits[length]!=9:
digits[length]+=1
return digits
else:
carry=0
for i in range(len(digits)-1,-1,-1):
if digits[i]==9:
digits[i]=0
carry=1
else:
if carry==1:
digits[i]+=1
carry=0
break
if carry==1:
lista=[]
lista.append(1)
for i in range(len(digits)):
lista.append(digits[i])
else:
lista=digits[:]
return lista
#second solution (easier)
""" number=''
for i in range(len(digits)):
number+=str(digits[i])
number=int(number)
number+=1
number=str(number)
lista=[]
for num in number:
lista.append(int(num))
return lista"""