238 Product of Array Except Self
238 Product of Array Except Self
从头部 和 尾部各扫描一遍
class Solution: # @param {integer[]} nums # @return {integer[]} def productExceptSelf(self, nums): ans = [1] for i in range(0, len(nums)-1): ans.append(ans[-1]*nums[i]) tmp = 1 for i in range(len(nums)-1,-1,-1): ans[i] *= tmp tmp *= nums[i] return ans