Very simple python solution using dp


  • 0
    G
    class Solution(object):
    def maxSubArray(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        max_notcon = -999999999999 
        max_con = nums[0] 
        for i in range(1,len(nums)): 
            max_notcon = max(max_notcon, max_con) 
            max_con = max(nums[i], max_con+nums[i]) 
        return max(max_notcon,max_con)

Log in to reply
 

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