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

连续子数组的最大和

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

public class Solution {
    public int FindGreatestSumOfSubArray(int[] array) {
        int thisSum=0, maxSum=array[0];
        for(int i=0;i<array.length;i++){
            thisSum+=array[i];
            if(thisSum>maxSum){
                maxSum=thisSum;
            }else if(thisSum<0){
                thisSum = 0;
            }
        }
        return maxSum;
    }
}
全部评论

相关推荐

09-12 11:55
已编辑
湖南工商大学 Java
那一天的Java_J...:这种一堆问题的,别去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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