Skip to content

Latest commit

 

History

History
21 lines (17 loc) · 444 Bytes

File metadata and controls

21 lines (17 loc) · 444 Bytes
class Solution(object):
    def productExceptSelf(self, nums):
        """
        :type nums: List[int]
        :rtype: List[int]
        """

        ans = [1]
        for i in range(1,len(nums)):
            ans.append(nums[i-1] * ans[i-1])
        
        back = 1
        for i in range(len(nums)-2, -1, -1):
            ans[i] *= back * nums[i+1]
            back *= nums[i+1]
            
        return ans

扫描 数组