We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 71f5eaf commit c4cd826Copy full SHA for c4cd826
add-one.py
@@ -0,0 +1,32 @@
1
+def add_one(arr):
2
+ output = 1
3
+ for i in range(len(arr),0,-1):
4
+ output = output + arr[i-1]
5
+ borrow = output//10
6
+ if(borrow == 0):
7
+ arr[i-1] = output
8
+ break
9
+ else:
10
+ arr[i-1] = output%10
11
+ output = borrow
12
+ arr = [borrow] + arr
13
+ index = 0
14
+ while arr[index] == 0:
15
+ index += 1
16
+ return arr[index: ]
17
+
18
+def test_function(test_case):
19
+ arr = test_case[0]
20
+ solution = test_case[1]
21
22
+ output = add_one(arr)
23
+ for index, element in enumerate(output):
24
+ if element != solution[index]:
25
+ print("Fail")
26
+ return
27
+ print("Pass")
28
29
+arr = [0]
30
+solution = [1]
31
+test_case = [arr, solution]
32
+test_function(test_case)
0 commit comments