Skip to content

Commit dd7a02a

Browse files
authored
Create 238-Product-of-array-except-self.py
1 parent a30838a commit dd7a02a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

238-Product-of-array-except-self.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
res = [1] * (len(nums))
4+
5+
prefix = 1
6+
for i in range(len(nums)):
7+
res[i] = prefix
8+
prefix *= nums[i]
9+
postfix = 1
10+
for i in range(len(nums) - 1, -1, -1):
11+
res[i] *= postfix
12+
postfix *= nums[i]
13+
return res
14+

0 commit comments

Comments
 (0)