66. Plus One
2016-09-08 本文已影响0人
a_void
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]
"""
def f(index):
if index < 0:
digits[0:0] = [1]
elif digits[index] < 9:
digits[index] += 1
else:
digits[index] = 0
return f(index - 1)
return digits
return f(len(digits)-1)