Skip to content

Commit ef71c9f

Browse files
committed
product of array except self solution
1 parent c79c692 commit ef71c9f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
# prefix, postfix probelm :(
3+
def productExceptSelf(self, nums: List[int]) -> List[int]:
4+
output = [1] * len(nums)
5+
6+
prefix = 1
7+
for i in range(len(nums)):
8+
output[i] = prefix
9+
prefix *= nums[i]
10+
11+
postfix = 1
12+
for i in range(len(nums) -1, -1, -1):
13+
output[i] *= postfix
14+
postfix *= nums[i]
15+
16+
return output

0 commit comments

Comments
 (0)