Skip to content

Commit 6d0e4b4

Browse files
committed
adding product-of-array-except-self
1 parent f2b5a10 commit 6d0e4b4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
4+
size = len(nums)
5+
6+
#initialize array as 1
7+
result = [1] * size
8+
9+
left_pass = 1
10+
11+
for i in range(size):A
12+
result[i] *= left_pass
13+
left_pass *= nums[i]
14+
15+
right_pass = 1
16+
for i in range(size-1, -1, -1):
17+
result[i] *= right_pass
18+
right_pass *= nums[i]
19+
20+
return result

0 commit comments

Comments
 (0)