Aleskighar


私信TA

用户名:1253300274

访问量:2763

签 名:

等  级
排  名 935
经  验 3327
参赛次数 0
文章发表 14
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:


解题思路:

注意事项:

参考代码:

public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] s=null;
    s=sc.nextLine().split(" ");
    //首先输入字符串的数组,中间用空格分隔
    int height[]=new int[s.length];
    //然后获取字符串长度,作为int[] 初始数组的长度
    for (int i=0;i<height.length;i++){
        height[i]=Integer.valueOf(s[i]);
        //再将String字符串数组转化为int数组。
    }
    System.out.println(maxArea(height));
}
public static int maxArea (int[] height) {
    //从两边进行逼近,每次放弃高度比较小的板
    int maxA=0;
    for(int right=0,left=height.length-1;right<left;){
        if(height[right]<height[left]){//右边的高度小,作为高
            maxA = Math.max(maxA,(left-right)*height[right]);
            right++;///放弃相对较小的高/
        }else{//左边的高度小,作为高
            maxA = Math.max(maxA,(left-right)*height[left]);
            left--;
        }
    }
    return maxA;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区