We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4652c72 commit dc23e61Copy full SHA for dc23e61
1 file changed
product-of-array-except-self/mrlee7.py
@@ -0,0 +1,18 @@
1
+from typing import List
2
+
3
4
+class Solution:
5
+ def productExceptSelf(self, nums: List[int]) -> List[int]:
6
+ result = [0] * len(nums)
7
8
+ prefix_product = 1
9
+ for index in range(len(nums)):
10
+ result[index] = prefix_product
11
+ prefix_product *= nums[index]
12
13
+ suffix_product = 1
14
+ for index in range(len(nums) - 1, -1, -1):
15
+ result[index] *= suffix_product
16
+ suffix_product *= nums[index]
17
18
+ return result
0 commit comments