Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def productExceptSelf(self, nums: List[int]) -> List[int]:
- res = [1] * (len(nums))
- prefix = 1
- for i in range(len(nums)):
- res[i] = prefix
- prefix *= nums[i]
- postfix = 1
- for i in range(len(nums) - 1, -1, -1):
- res[i] *= postfix
- postfix *= nums[i]
- return res
Advertisement
Add Comment
Please, Sign In to add comment