/**
     * 此为暴力解法
     * 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. sql中的高级编程(函数,存储过程,视图)

    一.函数:用sql写一个函数,调用这个函数,返回一张数据表table CREATE FUNCTION FunName ( ) RETURNS @TempTable table ( roleid int ...

  2. MYSQL中coalesce函数的用法

    coalesce():返回参数中的第一个非空表达式(从左向右依次类推): 例如: select coalesce(null,4,5); // 返回4 select coalesce(null,null ...

  3. Unity命令行打包

    http://www.66acg.com/?post=137 补充 unity编辑器端获取打包命令行自定义参数,这个可以获取到所有打包时的参数 string[] runArgs = System.En ...

  4. PJzhang:kali linux安装网易云音乐、Visual Studio Code、skype

    猫宁!!! 参考链接:https://blog.csdn.net/cloudatlasm/article/details/79183583 https://code.visualstudio.com/ ...

  5. 12pm 究竟是中午还是午夜

    12pm是中午=12noon12am是午夜=12midnightMN-midnight(午夜,中午) AM是after midnight开头字母 PM是prior to midnight开头字母正中午 ...

  6. python大战机器学习——支持向量机

    支持向量机(Support Vector Machine,SVM)的基本模型是定义在特征空间上间隔最大的线性分类器.它是一种二类分类模型,当采用了核技巧之后,支持向量机可以用于非线性分类. 1)线性可 ...

  7. oracle 列转行

    with temp as( as S3 from dual union all as S3 from dual ) select * from temp unpivot(Qty for Sizes i ...

  8. 渣渣菜鸡的 ElasticSearch 源码解析 —— 环境搭建

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/08/25/es-code01/ 软件环境 1.Intellij Idea:2018.2版本 2. ...

  9. mysql通过sql语句判断某个字段在一张表中是否存在

    应用场景: 我有一张表,表里面都是用户用来激活游戏的激活码,当用户在前端页面输入激活码时,要查询数据表中是否有这条激活码,如果有就返回"1",没有则返回"0". ...

  10. nginx的基本操作

    启动 nginx -c /etc/nginx/nginx.conf停止nginx -s stop nginx -s quit pkill -9 nginx重载nginx -s reload文件检测ng ...