class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int ans=nums[0];
        int sum=0;
        for(int num:nums){
            if(sum>0){
                sum+=num;
            }
            else{
                sum=num;
            }
            ans=max(ans,sum);
        }
        return ans;
    }
};
Last modification:July 30th, 2020 at 05:01 pm
如果觉得我的文章对你有用,请随意赞赏