Why does my code have "Memory Limit Exceeds"


  • 0
    A
    class Solution:
        # @param {integer[]} nums
        # @return {integer[]}
        def productExceptSelf(self, nums):
            
            if len(nums) <= 1: return []
            
            prod = [1]  * len(nums)
            
            for i in range(1, len(nums)):
                prod[i] = prod[i-1] * nums[i-1]
            
            RightProd = 1
            
            for i in range(len(nums)-2, -1, -1):
                RightProd = RightProd * nums[i+1] 
                prod[i] = prod[i+1] * RightProd
            
        return prod
    

    When I submit, it shows "Memory Limit Exceeds"? Why? Or any improvement?


Log in to reply
 

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