给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一。
最高位数字存放在数组的首位, 数组中每个元素只存储一个数字。
你可以假设除了整数 0 之外,这个整数不会以零开头。
示例 1:
输入: [1,2,3]
输出: [1,2,4]
解释: 输入数组表示数字 123。
解答:
class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
value = 0
length = len(digits)
for i in range(length):
value += digits[length-i-1]*pow(10,i)
value1 = value+1
res=[]
while (value1 != 0):
p = value1%10
value1 = value1/10
res.append(p)
return list(reversed(res))
```