Skip to content

Instantly share code, notes, and snippets.

@arkilis
Created March 30, 2016 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arkilis/fee68075dc24865a90807cb88bded79d to your computer and use it in GitHub Desktop.
Save arkilis/fee68075dc24865a90807cb88bded79d to your computer and use it in GitHub Desktop.
lc238_solution2
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