Solve 66. Plus One

This commit is contained in:
ktkovachev 2024-04-08 16:36:26 +01:00 committed by GitHub
parent fa8bbdeecb
commit fa5a35e24d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

9
python/66_plus_one Normal file
View File

@ -0,0 +1,9 @@
class Solution:
def plusOne(self, digits: List[int]) -> List[int]:
carry = 1
for current_index in range(len(digits)-1, -1, -1):
carry, digits[current_index] = divmod(digits[current_index]+carry, 10)
current_index -= 1
if carry == 1:
digits.insert(0, 1)
return digits