Skip to content

Commit 2d5705b

Browse files
committed
solved: 66. Plus One
Signed-off-by: rajput-hemant <[email protected]>
1 parent 4480f96 commit 2d5705b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: src/0001-0100/066 - Plus One/solution.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def plusOne(self, digits: list[int]) -> list[int]:
3+
carry = 0
4+
for i in range(len(digits) - 1, -1, -1):
5+
if i == len(digits) - 1:
6+
digits[i] += 1
7+
8+
digits[i] += carry
9+
carry = digits[i] // 10
10+
digits[i] %= 10
11+
12+
if carry:
13+
digits.insert(0, carry)
14+
return digits

0 commit comments

Comments
 (0)