Skip to content

Instantly share code, notes, and snippets.

@jbaek7023
Created June 7, 2018 14:58
Show Gist options
  • Save jbaek7023/2fe4b0db2db5303c3ddfb55a5ddbea3b to your computer and use it in GitHub Desktop.
Save jbaek7023/2fe4b0db2db5303c3ddfb55a5ddbea3b to your computer and use it in GitHub Desktop.
My Solution
class Solution:
def productExceptSelf(self, nums):
output = []
product = 1
for index in range(len(nums)):
product = 1 if index == 0 else product * nums[index-1]
output.append(product)
product = 1
for index in range(len(nums)-1, -1, -1):
product = 1 if len(nums)-1 == index else nums[index+1] * product
output[index] = product * output[index]
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment