题解 | #连续子数组的最大和#

连续子数组的最大和

http://www.nowcoder.com/practice/459bd355da1549fa8a49e350bf3df484

每次都取比当前数大的和,如果小于当前数,那么就重新计数

public class Solution {
    public int FindGreatestSumOfSubArray(int[] array) {
        int max=Integer.MIN_VALUE,i,k,l,op=0;
        for(int p : array){
            op = Math.max(op+p,p);
            max = Math.max(op,max);

        }
        return max;
    }
}
全部评论

相关推荐

星辰再现:裁员给校招生腾地方
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
05-29 20:12
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务