From fa5a35e24d534144759529a91ece02a7d1297334 Mon Sep 17 00:00:00 2001 From: ktkovachev <143198904+ktkovachev@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:36:26 +0100 Subject: [PATCH] Solve 66. Plus One --- python/66_plus_one | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 python/66_plus_one diff --git a/python/66_plus_one b/python/66_plus_one new file mode 100644 index 0000000..8343481 --- /dev/null +++ b/python/66_plus_one @@ -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