18 lines
454 B
Python
18 lines
454 B
Python
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])) |