zoukankan      html  css  js  c++  java
  • 求数组连续最大子串和

    import java.util.*;
    public class Main
        {
        public static void main(String[] args)
            {
            Scanner sr=new Scanner(System.in 
    
    );
            while(sr.hasNext())
                {
                String str=sr.nextLine();
                String[] strs=str.split(" ");
                int[] num=new int[strs.length];
                for(int i=0;i<strs.length;i++)
                  {
                    num[i]=Integer.valueOf(strs[i]);
                }  
                int sum=0;
                int max=Integer.MIN_VALUE;
                for(int i=0;i<num.length;i++)
                    {
                    sum+=num[i];
                    if(sum>max)
                        max=sum;
                    if(sum<0)
                        sum=0;
                }
                System.out.println(max);
            }
        }
    }
  • 相关阅读:
    如何为创建大量实例节省内存?
    4-5
    4-6
    4-4
    4-3
    4-2
    3-11
    4-1
    3-10
    3-8
  • 原文地址:https://www.cnblogs.com/mingyao123/p/7435626.html
Copyright © 2011-2022 走看看