97%, python solution


  • 0
    D
    def maxSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        if n == 1:
            return nums[0]
        x = nums[0]
        y = 0
        z = nums[0]
        for i in range(1,n):
            if x-y > z:
                z=x-y
            if x < y:
                y = x
            x+= nums[i]
        if x-y > z:
            z=x-y
        if x < y:
            y = x
            
        return z

  • 0
    C
    This post is deleted!

Log in to reply
 

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