Skip to content

Commit 7f66d1a

Browse files
authored
Merge pull request keon#69 from samakshjain/easier-plus-one
Add an easier solution to plus_one.py
2 parents 5730582 + c5405a9 commit 7f66d1a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

array/plus_one.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ def plus_one(digits):
3636
new_num = [0] * (n+1)
3737
new_num[0] = 1
3838
return new_num
39+
40+
41+
def plus_1(num_arr):
42+
for idx, digit in reversed(list(enumerate(num_arr))):
43+
num_arr[idx] = (num_arr[idx] + 1) % 10
44+
if num_arr[idx]:
45+
return num_arr
46+
return [1] + num_arr

0 commit comments

Comments
 (0)