Created
March 30, 2016 23:33
-
-
Save arkilis/fee68075dc24865a90807cb88bded79d to your computer and use it in GitHub Desktop.
lc238_solution2
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
def productExceptSelf2(self, nums): | |
""" | |
:type nums: List[int] | |
:rtype: List[int] | |
""" | |
aryRes = [] | |
for index in range(len(nums)): | |
#print nums[:index], nums[index+1:] | |
product_left = reduce(lambda x,y:x*y,nums[:index]) if(nums[:index]!=[]) else 1 | |
product_right = reduce(lambda x,y:x*y,nums[index+1:]) if(nums[index+1:]!=[]) else 1 | |
aryRes.append(product_left*product_right) | |
return aryRes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment