/**
     * 此为暴力解法
     * Find two lines, which together with x-axis forms a container, such that the container contains the most water.
     * @param height 高度
     * @return 面积
     */
    public int _maxArea(int[] height) {
        int area = 0;
        for(int i = 0; i < height.length; i++) {
            for(int j = i+1; j < height.length; j++) {
                int h = height[j] < height[i] ? height[j] : height[i];
                area = area > (j-i)*(h) ? area : (j-i)*(h);
            }
        }
        return area;
    }

    public int maxArea(int[] height) {
        int area = 0;
        // 两个指针
        int i = 0;
        int j = height.length-1;
        while(i < j) {
            int h = Math.min(height[i], height[j]);
            area = Math.max(area, (j - i) * (h));
            if(height[i] <= height[j]) {
                i++;
            } else {
                j--;
            }
        }
        return area;
    }

Array - Container With Most Water的更多相关文章

  1. leetcode 11. Container With Most Water 、42. Trapping Rain Water 、238. Product of Array Except Self 、407. Trapping Rain Water II

    11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情 ...

  2. LeetCode Array Medium 11. Container With Most Water

    Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...

  3. LeetCode:Container With Most Water,Trapping Rain Water

    Container With Most Water 题目链接 Given n non-negative integers a1, a2, ..., an, where each represents ...

  4. Leetcode11 Container With Most Water 解题思路 (Python)

    今天开始第一天记录刷题,本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 准备按tag刷,第一个tag是array: 这个是array的第一道题:11. Container With ...

  5. leetcode-algorithms-11 Container With Most Water

    leetcode-algorithms-11 Container With Most Water Given n non-negative integers a1, a2, ..., an , whe ...

  6. LeetCode解题报告—— Container With Most Water & 3Sum Closest & Letter Combinations of a Phone Number

    1.  Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a ...

  7. Container With Most Water(LintCode)

    Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a poi ...

  8. Leetcode 11. Container With Most Water(逼近法)

    11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...

  9. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

随机推荐

  1. Depth Buffer

    Up until now there is only one type of output buffer you've made use of, the color buffer. This chap ...

  2. 性能压测,SQL查询异常

    早上测试对性能压测,发现取sequence服务大量超时报错,查询线上的监控SQL: 大量这个查询,我在DeviceID和Isdelete上建有复合索引,应该很快,而且我测试了一下,取值,执行效率很高, ...

  3. C# 写 LeetCode easy #7 Reverse Integer

    7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 ...

  4. ue4 tags 与 cast

    父类设置tags,子类默认自动添加这个tags 子类可以强行删除父类的tags,这时如果把子类cast为父类,一样找不到这个tags 综上,要找到一个actor的tags,那么这个actor上就一定要 ...

  5. 使用ffmpeg编码时,如何设置恒定码率,并控制好关键帧I帧间隔

    1. 大家在使用ffmpeg进行视频编码时,使用-b命令,想控制比特率,却发现结果并没有如我们设置所愿,通过码流分析器观察视频码流,码率的波动还是很大的,ffmpeg控制的并不好,这时候,我们可以通过 ...

  6. 【转】Js 数组转JSON格式

    要点1:转化函数 JSON.stringify() 要点2:在js里写数组的时候是var data = new Array() 但是你如果是要转json显示的时候就要写成 var data = {}, ...

  7. Picture poj1177

    Picture Time Limit: 2000MS   Memory Limit: 10000K Total Submissions: 12265   Accepted: 6484 Descript ...

  8. uoj#351. 新年的叶子(概率期望)

    传送门 数学还是太差了,想了半天都没想出来 首先有一个定理,如果直径(这里考虑经过的点数)为奇数,所有直径有同一个中点,如果直径为偶数,所有直径有同一条最中间的边.这个可以用反证法,假设不成立的话直径 ...

  9. Maven项目编译版本的问题和Spring中没有导入核心包

    idea中maven项目的编译: 方案1:maven的settings.xml中指定全局默认编译版本 <profile> <id>jdk-1.8</id> < ...

  10. jquery.jscrollpane.js滚动速度设置

    首先找到插件里面的这个函数,改变成下面的样子: function initMousewheel() { container.unbind(mwEvent).bind( mwEvent, functio ...