Skip to content

Commit 60654ad

Browse files
committed
Create 66. Plus One.py
1 parent cffe172 commit 60654ad

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

66. Plus One.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
# @Time : 2019/2/27 11:18
3+
# @Author : xulzee
4+
5+
# @File : 66. Plus One.py
6+
# @Software: PyCharm
7+
from typing import List
8+
9+
10+
class Solution:
11+
def plusOne(self, digits: List[int]) -> List[int]:
12+
l = len(digits)
13+
digits[l - 1] += 1
14+
j = l - 1
15+
while digits[j] >= 10:
16+
if j == 0:
17+
digits[j] = 0
18+
digits.insert(0, 1)
19+
return digits
20+
digits[j] = 0
21+
j -= 1
22+
digits[j] += 1
23+
return digits
24+
25+
26+
if __name__ == '__main__':
27+
N = [0]
28+
print(Solution().plusOne(N))

0 commit comments

Comments
 (0)