您的位置:首页 > 其它

最大子序列和算法

2017-08-26 21:17 197 查看
最大子序列和,数组中从k到m的子序列的最大和问题

public void maxSum() {
int a[] = {1, 2, 5, 3, -15, 8};

int thisNum = 0;
int maxNum = 0;
for (int i = 0; i < a.length; i++) {
thisNum += a[i];
if (thisNum > maxNum) {
maxNum = thisNum;
} else if (thisNum < 0) {
thisNum = 0;
}
}
System.out.println("maxNum:"+maxNum);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  算法