Product of Array Except Self
要点:和Candy之类的都是一个路数,注意这题已经限定了n>1,所以不用考虑n<=1的边界条件
class Solution(object):
def productExceptSelf(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
n = len(nums)
res = [0]*n
res[0]=1
for i in xrange(1, n):
res[i]=res[i-1]*nums[i-1]
right = 1
for i in xrange(n-1,-1,-1):
res[i]=res[i]*right
right*=nums[i]
return res