Skip to content

Commit

Permalink
Time: 160 ms (82.64%) | Memory: 25 MB (11.12%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Mar 15, 2024
1 parent e46a851 commit af1086c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 238-product-of-array-except-self/product-of-array-except-self.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
n = len(nums)

prefix = [1] * n
suffix = [1] * n

for i in range(1, n):
prefix[i] = prefix[i - 1] * nums[i - 1]

for i in range(n - 2, -1, -1):
suffix[i] = suffix[i + 1] * nums[i + 1]

answer = [prefix[i] * suffix[i] for i in range(n)]

return answer

0 comments on commit af1086c

Please sign in to comment.