238 Product of Array except itself
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
class Solution:
|
||||||
|
def productExceptSelf(self, nums: list[int]) -> list[int]:
|
||||||
|
ans = [1] * len(nums)
|
||||||
|
curr = 1
|
||||||
|
for i in range(len(nums)):
|
||||||
|
ans[i] *= curr
|
||||||
|
curr *= nums[i]
|
||||||
|
|
||||||
|
curr = 1
|
||||||
|
for i in range(len(nums) - 1, -1, -1):
|
||||||
|
ans[i] *= curr
|
||||||
|
curr *= nums[i]
|
||||||
|
return ans
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
test = Solution()
|
||||||
|
|
||||||
|
print(test.productExceptSelf([-1,1,0,-3,3]))
|
||||||
Reference in New Issue
Block a user