力扣题51~55-题53(中等):

时间:2024-10-20 17:07:32

分析:

python代码:

class Solution:
    def maxSubArray(self, nums: List[int]) -> int:
        #不用看也是动态规划啊,每一个现状等于之前状态加判断
        res=0
        n_len=len(nums)
        n_list=[0 for i in range(n_len)]
        for i in range(n_len):
            n_list[i]=max(nums[i],n_list[i-1]+nums[i])
        res=max(n_list)
        return res