zoukankan      html  css  js  c++  java
  • 数组最大和 编程题

    package math;

    public class MaxSum {
     public static int maxSum(int arr[]){
      int sum = arr[0];
         int b = 0;
         for(int i=0;i<arr.length;i++){
          if(b<=0){
           b = arr[i];
          }else
            b+=arr[i];
           if(b>sum)sum=b;
           }
           return sum;
           
          }
         public static void main(String[] args){
          int arr[] = {-1,-2,-3,-10,-4,-7,-2,-5};
          int result = maxSum(arr);
          System.out.println(result);
         }
     
     }

    下面是结果:

  • 相关阅读:
    MySQL
    php抽象类和接口
    php面向对象三大特征
    php面向对象
    Git
    css3属性
    数据渲染
    ajax(2)
    ajax笔记
    作用域面试题
  • 原文地址:https://www.cnblogs.com/LT1997/p/6562346.html
Copyright © 2011-2022 走看看