最大子序列和问题的求解【原】

/**

* 求最大子序列和

* @param a

* @return

*/

public static int maxSubSum(int[] a ){

int maxSum = 0,thisSum = 0;

int length = a.length;

for (int i = 0; i < length; i++) {

thisSum += a[i];

if (thisSum>maxSum) {

maxSum = thisSum;

}else if(thisSum < 0 ){

thisSum = 0;

}

}

return maxSum;

}

你可能感兴趣的:(序列)