Problem
Bits of a number is divided into a list. Increase the last bit.
Algorithm
If the last bit is bigger than 9, increase the front bits.
Code
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
sLen = len(digits)
inc = 1
ans = []
for i in range(sLen-1, -1, -1):
digits[i] = digits[i] + inc
if digits[i] > 9:
digits[i] -= 10
inc = 1
else:
inc = 0
ans.append(digits[i])
if inc:
ans.append(inc)
return reversed(ans)