10000 optimal solution of sum of list · htudu/python_exercise@f571957 · GitHub
[go: up one dir, main page]

Skip to content

Commit f571957

Browse files
author
puja kumari
committed
optimal solution of sum of list
1 parent bab9c5a commit f571957

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

puja/sum_of_list.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# original
12
num = [1,4,6,7,2,8]
23
sum = 6
34

@@ -9,4 +10,13 @@ def sum_of_no(num,sum):
910
return i , j
1011
# print(f" sum of {i} + {j} = {total}")
1112

12-
print(sum_of_no(num , sum))
13+
print(sum_of_no(num , sum))
14+
15+
# optimal solution
16+
17+
def sum_of_num(num, sum):
18+
for i in num:
19+
x = sum - i
20+
if x in num:
21+
return i, x
22+
print(sum_of_num(num, sum))

0 commit comments

Comments
 (0)
0