66. Plus One
Input: [1,2,3]
Output: [1,2,4]
Explanation: The array represents the integer 123.Input: [4,3,2,1]
Output: [4,3,2,2]
Explanation: The array represents the integer 4321.class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
overflow = 0
digits[len(digits)-1] += 1
for i in range(len(digits)-1, -1, -1):
digits[i] += overflow
overflow = 0
if digits[i] == 10:
digits[i] = 0
overflow = 1
if overflow == 1:
digits.insert(0, overflow)
return digitsLast updated