class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param array int整型vector
* @return int整型vector
*/
vector<int> FindGreatestSumOfSubArray(vector<int>& array) {
// write code here
int max=INT_MIN;
int index=0;
int start=0;
int lenth=0;
int curnum=0;
if(array.size()==0){
return array;
}
for(int i=0;i<array.size();i++){
curnum+=array[i];
if(curnum<0){
if(curnum>max){
max=curnum;
lenth=i-start+1;
index=start;
}
curnum=0;
start=i+1;
}
else{
if(curnum>max){
max=curnum;
lenth=i-start+1;
index=start;
}
else if(curnum==max){
if(i-start+1>lenth){
lenth=i-start+1;
index=start;
}
}
}
}
vector<int> res;
for(int i=index;i<index+lenth;i++){
res.push_back(array[i]);
}
return res;
}
};
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param array int整型vector
* @return int整型vector
*/
vector<int> FindGreatestSumOfSubArray(vector<int>& array) {
// write code here
int max=INT_MIN;
int index=0;
int start=0;
int lenth=0;
int curnum=0;
if(array.size()==0){
return array;
}
for(int i=0;i<array.size();i++){
curnum+=array[i];
if(curnum<0){
if(curnum>max){
max=curnum;
lenth=i-start+1;
index=start;
}
curnum=0;
start=i+1;
}
else{
if(curnum>max){
max=curnum;
lenth=i-start+1;
index=start;
}
else if(curnum==max){
if(i-start+1>lenth){
lenth=i-start+1;
index=start;
}
}
}
}
vector<int> res;
for(int i=index;i<index+lenth;i++){
res.push_back(array[i]);
}
return res;
}
};