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 cc399a2 commit 3742f29Copy full SHA for 3742f29
product-of-array-except-self/paran22.py
@@ -0,0 +1,18 @@
1
+class Solution:
2
+ # time complexity: O(n)
3
+ def productExceptSelf(self, nums: List[int]) -> List[int]:
4
+ n = len(nums)
5
+ answer = [1] * n
6
+
7
+ prefix = 1
8
+ for i in range(n):
9
+ answer[i] = prefix
10
+ prefix *= nums[i]
11
12
+ suffix = 1
13
+ for i in range(n-1, -1, -1):
14
+ answer[i] *= suffix
15
+ suffix *= nums[i]
16
17
+ return answer
18
0 commit comments