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.
Subscribe to see which companies asked this question
class Solution(object):
def plusOne(self, digits):
"""
:type digits: List[int]
:rtype: List[int]
"""
flag = False
for i in range(len(digits))[::-1]:
digits[i] += 1
if digits[i] == 10:
digits[i] = 0
else:
flag = True
break
if not flag:
digits.insert(0,1)
return digits