美文网首页LeetCode
53. 最大子序和

53. 最大子序和

作者: cptn3m0 | 来源:发表于2019-03-19 14:01 被阅读0次

极简版代码

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

相关文章

网友评论

    本文标题:53. 最大子序和

    本文链接:https://www.haomeiwen.com/subject/ybmgmqtx.html