zoukankan      html  css  js  c++  java
  • 百度面试题

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package maxsum;
    class sum
    {
    int array1[];
    int arrayend[]={0,0,0};
    public sum(){}
    public sum(int i){
    array1=new int[i];
    for(int j=0;j<array1.length;j++)
    {
    array1[j] = (int) (Math.random() * 26)-10;
    System.out.print(array1[j]+" ");
    }
    }
    public void findMaxSumCM() {
    int head = 0;
    int sum = 0;
    int arrayend[] = {0, 0, 0};//保存最大值,起点,终点;

    System.out.println();
    for (int i = 0; i < array1.length; i++) {
    sum = sum + array1[i];
    if (sum < 0)//丢弃
    {
    sum = 0;
    if (i != array1.length - 1) //如果下标到头,则不做任何处理
    //如果下小不到头
    {
    head = i + 1;
    }
    } else//处理
    {
    if (sum > arrayend[0])//如果此sum>此前存的值,则替换之。
    {
    arrayend[0] = sum;
    arrayend[1] = head;
    arrayend[2] = i;
    }

    }
    }
    System.out.print("\n");
    System.out.println("sum=" + arrayend[0] + " 下标= " + arrayend[1] + "终点= " + arrayend[2]);
    }
    }
    /**
    *
    * @author Administrator
    */
    public class MaxSum {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    sum sm=new sum(10);
    sm.findMaxSumCM();
    }
    }

  • 相关阅读:
    Service Discovery
    Spring security框架原理
    Redis作者谈Redis应用场景
    redis持久化RDB和AOF-转载
    MongoDB树形结构表示法
    Tomcat Connector
    ActiveMQ 负载均衡与高可用(转载)
    JS选取DOM元素的方法
    IObit Driver Booster 无法更新驱动的解决办法
    python 学习备忘
  • 原文地址:https://www.cnblogs.com/xiekai/p/3488130.html
Copyright © 2011-2022 走看看