Easy Understand Python Version (56ms, beat 51%)


  • 0
    A
    def maxSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """      
        # -2 -1 -4 0 -1 1 2 -3 1 
        summ=[0]
        for i in range(0,len(nums)):
            summ.append(summ[-1]+nums[i])
        maxv=-float('inf')
        maxd=-float('inf')
        for j in range(len(summ)-1,-1,-1):
            if maxv-summ[j]>maxd:
                maxd=maxv-summ[j]
            if summ[j]>maxv:
                maxv=summ[j]
            
        return maxd

Log in to reply
 

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