最大子序列和求解 最优算法O(N)

来源:互联网 发布:php bin2hex 编辑:程序博客网 时间:2024/05/16 10:28
/*** Linear-time maximum contiguous subsequence sum algorithm.*/int maxSubSum4(const vector<int> & a){    int maxSum=0,thisSum=0;    for( int j=0;i<a.size();j++)    {       thisSum+=a[j];       if(thisSum>maxSum)           maxSum=thisSum;       else if( thisSum < 0 )            thisSum=0;    }    retrun maxSum;}
0 0