您的位置:首页 > 其它

leetcode Plus One

2015-12-11 20:08 405 查看
原题链接:https://leetcode.com/problems/plus-one/

Description

Given a non-negative number represented as an array of digits, plus one to the number.

The digits are stored such that the most significant digit is at the head of the list.

class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
for i in reversed(range(len(digits))):
if digits[i] == 9:
digits[i] = 0
if i == 0:
digits.insert(0, 1)
else:
digits[i] += 1
break
return digits
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: