int MaxSubSeqSum(int arr[], int n) {
int currentSum, maxSum;
currentSum = maxSum = 0;
for(int i=0; i<n; i++) {
currentSum += arr[i]; /* 向右累加 */
if(currentSum > maxSum) { /* 发现更大值 更新最大值 */
maxSum = currentSum;
}else if(currentSum < 0){ /* 如果当前子列为负 舍弃 置零 */
currentSum = 0;
}
}
return maxSum;
}
网友评论