最大子列和,在线处理

 

  

public class day0527 {
    public static void main(String[] args) {

        int arr[]=new int[]{2,3,5,-5,6,-4,6,9,31,-21};
        int maxSum=0,thisSum=0;
        for (int i = 0; i <arr.length ; i++) {
            thisSum+=arr[i];
            if (thisSum>maxSum){
                maxSum=thisSum;
            }
            else if(thisSum<0){
                thisSum=0;
            }
        }
        System.out.println(maxSum);
    }
}

  

posted @ 2019-05-27 22:27  耿红军  阅读(209)  评论(0编辑  收藏  举报