- 40ms
- 41%
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
carry = 1
n = len(digits)
if n == 0: return digits
for idx in range(len(digits)-1, -1, -1):
carry, digits[idx] = divmod(carry+digits[idx], 10)
if carry == 0: break
if carry == 0:
return digits
return [carry] + digits