Python DP solution


  • 0
    Y
    class Solution(object):
        def maxSubArray(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            max_ending_here, max_ending_sofar = nums[0], nums[0]
            for n in nums[1:]:
                max_ending_here = max(max_ending_here + n, n)
                max_ending_sofar = max(max_ending_sofar, max_ending_here)
            return max_ending_sofar
    

Log in to reply
 

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