(1)the obvious O(N^3) algorithm









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;
seqStart =i;
seqEnd =j;
}
}
return maxSum;
}



an improved O(N^2) algorithm
在O(N^3)基础上改进:除去了最内的循环原因在于重复的计算thisSum是不必要的





























a linear algorithm
Theorem : any i, let Ai..j be the first sequence ,with Si..j<0. Then ,for any i<=p<=j and
p<=q,Ap..q either is not a maximum contiguous subsequence or is equal to an
already seen maximum contiguous subsequence
证明略。





























