Skip to content

Commit 7ab60db

Browse files
committed
feat: add product of array except self solution
1 parent 7f64711 commit 7ab60db

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def productExceptSelf(self, nums: List[int]) -> List[int]:
6+
result = []
7+
8+
product = 1
9+
for i in range(len(nums)):
10+
result.append(product)
11+
product *= nums[i]
12+
13+
product = 1
14+
15+
for i in range(len(nums) - 1, -1, -1):
16+
result[i] *= product
17+
product *= nums[i]
18+
19+
return result

0 commit comments

Comments
 (0)