Skip to content

Commit 0ffe489

Browse files
authored
Update problem1_n_2
1 parent 497ae21 commit 0ffe489

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

daily_coding_problems/problem1_n_2

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ In order to find the product of numbers before i, we can generate a list of pref
8383
#This runs in O(N) time and space, since iterating over the input arrays takes O(N) time and creating the prefix and suffix arrays take up O(N) space.
8484

8585
#Solution by division:
86+
from functools import reduce
8687
def products(lst):
87-
full_multiple = 1
88-
for x in lst:
89-
full_multiple *= x
90-
88+
#full_multiple = 1
89+
#for x in lst:
90+
# full_multiple *= x
91+
full_multiple = reduce(lambda a,b: a*b, lst)
9192
result = []
9293
for num in lst:
9394
result.append(int(full_multiple/num))

0 commit comments

Comments
 (0)