53. 최대 하위 배열 합계

제목 설명:

여기에 이미지 설명 삽입

주요 아이디어:

이것은 또 다른 동적 프로그래밍 문제이지만 이 문제는 후유증이 없기 때문에 동적 프로그래밍으로 간주되지 않습니다.

class Solution {
    
    
public:
    int maxSubArray(vector<int>& nums) {
    
    
        int ans=-100000000;
        int nowans=0;
        for(auto num:nums)
        {
    
    
            nowans=max(nowans+num,num);
            ans=max(ans,nowans);
        }
        return ans;
    }
};

추천

출처blog.csdn.net/weixin_54385104/article/details/129987253