class Solution {
public:
int maxSubArray(vector<int>& nums)
{
const int n=nums.size();
int MaxSum=nums[0];
int curMax=nums[0];
for(int i=1;i<n;++i)
{
if(curMax<0)
curMax=nums[i];
else
curMax+=nums[i];
MaxSum=max(curMax,MaxSum);
}
return MaxSum;
}
};
Maximum Subarray
最新推荐文章于 2021-04-28 15:29:26 发布