Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4fe92d0

Browse files
add python solution of 66
1 parent 5cff9ed commit 4fe92d0

File tree

2 files changed

+51
-1
lines changed
  • codes/python/leetcodes/src/main/python/com/hit/basmath/learn/array_and_string

2 files changed

+51
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ You can also ask for problem solving ideas and discuss in GitHub issues directly
5454
|27|[Remove Element](https://leetcode.com/problems/implement-strstr/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_27.java) & Python|![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Two-Pointer Technique
5555
|28|[Implement strStr()](https://leetcode.com/problems/implement-strstr/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_28.java) & Python|![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Introduction to String
5656
|54|[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_54.java) & Python|![medium](https://github.com/guobinhit/myleetcode/blob/master/images/medium.png)| Introduction to 2D Array
57-
|66|[Plus One](https://leetcode.com/problems/plus-one/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_66.java) & Python|![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Introduction to Array
57+
|66|[Plus One](https://leetcode.com/problems/plus-one/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_66.java) & [Python](https://github.com/guobinhit/myleetcode/blob/master/codes/python/leetcodes/src/main/python/com/hit/basmath/learn/array_and_string/_66.py)|![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Introduction to Array
5858
|67|[Add Binary](https://leetcode.com/problems/add-binary/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_67.java) & Python|![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Introduction to String
5959
|118|[Pascal's Triangle](https://leetcode.com/problems/pascals-triangle/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_118.java) & Python| ![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Introduction to 2D Array
6060
|119|[Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii/description/)|[Java](https://github.com/guobinhit/myleetcode/blob/master/codes/java/leetcodes/src/main/java/com/hit/basmath/learn/array_and_string/_119.java) & Python| ![easy](https://github.com/guobinhit/myleetcode/blob/master/images/easy.png)| Conclusion
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
66. Plus One
3+
4+
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.
5+
6+
The digits are stored such that the most significant digit is at the head of the list, and each element in the array contain a single digit.
7+
8+
You may assume the integer does not contain any leading zero, except the number 0 itself.
9+
10+
Example 1:
11+
12+
Input: [1,2,3]
13+
Output: [1,2,4]
14+
Explanation: The array represents the integer 123.
15+
16+
Example 2:
17+
18+
Input: [4,3,2,1]
19+
Output: [4,3,2,2]
20+
Explanation: The array represents the integer 4321.
21+
22+
Example 3:
23+
24+
Input: [9,9]
25+
Output: [1,0,0]
26+
Explanation: The array represents the integer 99.
27+
"""
28+
29+
30+
class Solution(object):
31+
def plusOne(self, digits):
32+
"""
33+
:type digits: List[int]
34+
:rtype: List[int]
35+
"""
36+
i = len(digits) - 1
37+
while i >= 0:
38+
if digits[i] < 9:
39+
digits[i] = digits[i] + 1
40+
return digits
41+
else:
42+
digits[i] = 0
43+
44+
i -= 1
45+
46+
digits2 = [1]
47+
for i in range(len(digits)):
48+
digits2.append(0)
49+
50+
return digits2

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /