Skip to content

Commit 1f4207a

Browse files
committed
add: product-of-array-except-self solved
1 parent f7461ac commit 1f4207a

File tree

1 file changed

+17
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)