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