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

连续子数组的最大和

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;
    }
}
全部评论

相关推荐

暮雨轻歌:看起来hr不能接受我菜查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务