Simple DP in Python


  • -1
    X
    class Solution(object):
        def maxSubArray(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            n = len(nums)
            dp = [0]*(n)
            dp[0] = nums[0]
            for i in range(1,n):
                dp[i] = max(dp[i-1] + nums[i], nums[i])
            return max(dp)

Log in to reply
 

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