Skip to content

Commit 90bea1d

Browse files
committed
product-of-array-except-self solution
1 parent af92506 commit 90bea1d

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+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
4+
answer = [1]*len(nums)
5+
6+
left = 1
7+
for i in range(len(nums)):
8+
answer[i] *= left
9+
left *= nums[i]
10+
11+
right = 1
12+
for i in range(len(nums)-1,-1,-1):
13+
answer[i] *= right
14+
right *= nums[i]
15+
16+
return answer

0 commit comments

Comments
 (0)