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):
l = len(digits)
d = digits
p = 1 #表示进位
for i in range(l-1,-1,-1):
res = d[i] + p
if res > 9:
d[i] = (res-10)
p = 1
else:
d[i] = res
p = 0
if p == 1:
d = [1]+d
return d
"""
:type digits: List[int]
:rtype: List[int]
"""

本文介绍了一种使用Python解决给定非负整数数组并加一的问题的方法,包括类定义、方法实现以及实例演示。
570

被折叠的 条评论
为什么被折叠?



