Very fast and easy Python


  • 0
    M
    class Solution:
        def productExceptSelf(self, nums):
            """
            :type nums: List[int]
            :rtype: List[int]
            """
            # nums: 2  3   5  1
            # prd : 1  2   6  30
            # mul : 15  5   1   1
            # ans:  15   10   6    30
            
            products=[0 for _ in nums]
            mul =1
            
            for i in range(len(nums)):
                products[i] = mul
                mul *= nums[i]
            
            mul =1
            for i in range(len(nums)-1 , -1 ,-1):
                products[i] *= mul
                mul *= nums[i]
            
            return products
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.