Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created March 28, 2021 21:45
Show Gist options
  • Select an option

  • Save mvallebr/91c934fe76185e14eb425a921f1b18c0 to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/91c934fe76185e14eb425a921f1b18c0 to your computer and use it in GitHub Desktop.
import math
class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
result = [0] * len(nums)
product = 1
for i in range(len(nums) -1, -1, -1):
product *= nums[i]
result[i] = product
product = 1
for i in range(len(nums)):
next_one = result[i+1] if i < len(result)-1 else 1
result[i] = product * next_one
product *= nums[i]
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment