其他分享
首页 > 其他分享> > LC 918. Maximum Sum Circular Subarray

LC 918. Maximum Sum Circular Subarray

作者:互联网

link

 

 

class Solution {
public:
    int maxSubarraySumCircular(vector<int>& A) {
        int maxsum=INT_MIN;
        int minsum=INT_MAX;
        int total=0;
        int curmax=0;
        int curmin=0;
        for(int i=0;i<A.size();i++){
            curmax=max(curmax+A[i],A[i]);
            curmin=min(curmin+A[i],A[i]);
            maxsum=max(maxsum,curmax);
            minsum=min(minsum,curmin);
            total+=A[i];
        }
        return total==minsum?maxsum : max(maxsum,total-minsum);
    }
};

 

标签:LC,int,Sum,Maximum,INT,minsum,curmin,maxSubarraySumCircular
来源: https://www.cnblogs.com/FEIIEF/p/12898699.html