66. Plus One [python]
2018-02-28 22:20
267 查看
题目:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits are stored such that the most significant digit is at the head of the list.就是说一组数表示成数组形式,然后加一把她仍写成数组,如999 + 1 = 1000, [9, 9, 9]-->[1, 0, 0, 0]程序:class Solution:
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
N = len(digits)
i = N-1
while digits[i] == 9:
digits[i] = 0
if i == 0:
digits.insert(0,1)
return digits
else:
i -= 1
digits[i] += 1
return digits
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
N = len(digits)
i = N-1
while digits[i] == 9:
digits[i] = 0
if i == 0:
digits.insert(0,1)
return digits
else:
i -= 1
digits[i] += 1
return digits
相关文章推荐
- [Leetcode]@python 66. Plus One
- LeetCode OJ 系列之66 Plus One --Python
- LeetCode66. Plus One-python(easy)
- 【LeetCode 66】Plus One(Python)
- 66. Plus One [easy] (Python)
- 66. Plus One (python)
- [leetcode:python]66.Plus One
- [LeetCode By Python]66. Plus One
- LeetCode 66 Plus One (Python详解及实现)
- LeetCode 66 — Plus One(C++ Java Python)
- Leetcode-66. Plus One
- leetcode 66. Plus One
- LeetCode 66. Plus One
- 【LeetCode】66. Plus One
- 【LeetCode】66. Plus One
- leetcode 66. Plus One
- LeetCode 66. Plus One
- 【leetcode】66. Plus One
- 66. Plus One徒手尝试#2(Done)
- Leetcode[66]-Plus One