"""
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.
You may assume the integer do not contain any leading zero, except the number 0 itself.
The digits are stored such that the most significant digit is at the head of the list.
"""
"""
TESTCASES:
Input:
[0]
[1,2,3]
[1,2,9]
[9,9]
Output:
[1]
[1,2,4]
[1,3,0]
[1,0,0]
"""
class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
res = [];
flag = 1;
for i in range(len(digits) - 1, -1 ,-1):
temp = (digits[i] + flag) / 10;
res.append((digits[i] + flag) % 10);
flag = 1 if temp else 0;
if flag == 1:
res.append(1);
return res[::-1];