#!/bin/python3

#Given a non-negative integer represented as a non-empty array of digits,
# plus one to the integer.
class Solution(object):
	def plusOne(self, digits):
		"""
		:type digits: List[int]
		:rtype: List[int]
		"""
		index = len(digits)-1
		digits[index] += 1
 
		for i in reversed(range (0, len(digits))):
			if digits[i]>9:
				digits[i], digits[i-1] = 0, digits[i-1]+1

		#if digits[0]>9:
		#	digits[0] = 0
		#	digits.insert(0, 0)

		return digits

def main():

	print ("plus one")
	sol = Solution()
	#nums = [2, 7, 7, 7]
	nums = [9, 9, 9, 9]

	result = sol.plusOne(nums)

	print(result)

if __name__=="__main__":main()
