8000 66, check current digit is 9 or not · xzlin/LeetCode_Python_Accepted@f6e8560 · GitHub
[go: up one dir, main page]

Skip to content

Commit f6e8560

Browse files
committed
66, check current digit is 9 or not
1 parent af6a43d commit f6e8560

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

66_Plus_One.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
# 2015-05-11 Runtime: 63 ms
2-
class Solution:
3-
# @param {integer[]} digits
4-
# @return {integer[]}
1+
# 2016-03-27 108 tests, 40 ms
2+
class Solution(object):
53
def plusOne(self, digits):
6-
for i in reversed(xrange(len(digits))):
7-
if digits[i] < 9:
8-
digits[i] += 1
4+
"""
5+
:type digits: List[int]
6+
:rtype: List[int]
7+
"""
8+
for i, d in enumerate(reversed(digits), start = 1):
9+
if d < 9:
10+
digits[-i] += 1
911
return digits
1012
else:
11-
digits[i] = 0
12-
digits.insert(0, 1)
13-
return digits
13+
digits[-i] = 0
14+
return [1] + digits

0 commit comments

Comments
 (0)
0