/**
* 算法一
*/
public int maxSubSum(int []a){
int maxSum = 0;
for(int i=0;i<a.length;i++){
for(int j = i;j<a.length;j++){
int thisSum = 0;
for(int k = i;k<j;k++){
thisSum += a[k];
}
if(thisSum>maxSum){
maxSum = thisSum;
}
}
}
return maxSum;
}
/**
* 算法二
*/
public int maxSubSumSecond(int []a){
int maxSum = 0;
for(int i=0;i<a.length;i++){
int thisSum = 0;
for(int j=i;j<a.length;j++){
thisSum += a[j];
if(thisSum > maxSum){
maxSum = thisSum;
}
}
}
return maxSum;
}
/**
* 算法三
*/
public int maxSubSumThird(int []a){
int maxSum = 0;
int thisSum = 0;
for(int i=0;i<a.length;i++){
thisSum += a[i];
if(thisSum>maxSum){
maxSum = thisSum;
}
else if(thisSum<0) {
thisSum = 0;
}
}
return maxSum;
}