class Solution {
public:
int maxSubArray(vector<int>& nums) {
int thissum = 0,maxsum;
int i,j;
maxsum = nums[i];
for(i = 0;i < nums.size();i++)
{
thissum = 0;
for(j = i;j < nums.size();j++)
{
thissum += nums[j];
if(thissum > maxsum)
{
maxsum = thissum;
}
}
}
return maxsum;
}
};
力扣刷题 13.最大子序和——简单题
最新推荐文章于 2024-08-16 19:16:34 发布