#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
int FindGreatestSumOfSubArray(vector<int> array) {
int max = -2147483648;
int i = 0;
int size = array.size();
for (i = 0; i <= size - 1; i++)
{
int m = i ;
int sum = 0;
int max1 = -2147483648;
for (; m <=size - 1; m++)
{
sum = sum + array[m];
if (sum>max1)
{
max1 = sum;
}
}
if (max1 > max)
max = max1;
}
return max;
}
};
class Solution {
public:
int FindGreatestSumOfSubArray(vector<int> array) {
if (array.empty()) return 0;
int max_s = array[0];
int sum = array[0];
for (int i = 1; i < array.size(); ++i){
sum += array[i];
max_s = max(max_s, sum);
sum = max(sum, 0);
}
return max_s;
}
};
public int FindGreatestSumOfSubArray(int[] array) {
int res = array[0]; //记录当前所有子数组的和的最大值
int max = array[0]; //包含array[i]的连续数组最大值
for (int i = 1; i < array.length; i++) {
max = Math.max(max + array[i], array[i]);
res = Math.max(max, res);
}
return res;
}