Created
June 7, 2018 14:58
-
-
Save jbaek7023/2fe4b0db2db5303c3ddfb55a5ddbea3b to your computer and use it in GitHub Desktop.
My Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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