题目:
https://leetcode-cn.com/problems/maximum-subarray
代码:
class Solution {
public:
int maxSubArray(vector& nums) {
int size = nums.size();
if(size == 0)
return 0;
int res = nums[0];
for(int i =0 ; i < size; i++)
{
int sum = 0;
for(int l = i ; l < size; l++)
{
sum += nums[l];
if(sum > res)
res = sum;
}
}
return res;
}
};
结果: