/**
     * 此为暴力解法
     * 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. HDU - 1176 免费馅饼 DP多种状态转移

    免费馅饼 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了 ...

  2. CodeForces - 505B Mr. Kitayuta's Colorful Graph 二维并查集

    Mr. Kitayuta's Colorful Graph Mr. Kitayuta has just bought an undirected graph consisting of n verti ...

  3. JAVA基础--IO输入输出(File使用)17

    一. File中的方法 1.  列举方法 /* * 获取指定目录以及子目录下的所有文件和文件夹 */ public class ListFilesDemo { public static void m ...

  4. 讨论:研发团队到底应该是制定OKR还是制定KPI?

    在讨论之前我们先来了解两个概念: 一.KPI KPI是一套绩效管理的方法.全称为:Key Performance Indicator.中文叫:关键绩效指标. KPI,和我们的“任务分解”不同.任务分解 ...

  5. 【Java面试题系列】:Java基础知识常见面试题汇总 第二篇

    文中面试题从茫茫网海中精心筛选,如有错误,欢迎指正! 第一篇链接:[Java面试题系列]:Java基础知识常见面试题汇总 第一篇 1.JDK,JRE,JVM三者之间的联系和区别 你是否考虑过我们写的x ...

  6. eclipse中设置vm后缀文件以html高亮形式显示

    第一步,打开Windows-preference-General-ContentTypes-Text-HTML 第二步,点击Add添加 "*.vm",Default-encodin ...

  7. Prefix.pch文件的用法

    我们知道,每新建立一个工程,比如说HelloWord,在分类SupportingFiles里都会有一个以工程名开头-Prefix.pch结尾的文件,如HelloWord-Prefix.pch.对于这个 ...

  8. angularJs 自定义指令传值---父级与子级之间的通信

    angularJs自定义指令用法我忽略,之前有写过,这里只说一下父子级之间如何传值: 例如: 模块我定义为myApp,index.html定义 <my-html bol-val="bo ...

  9. jquery获取文档高度和窗口高度汇总

    jquery获取窗口高度和窗口高度,$(document).height().$(window).height() $(document).height():整个网页的文档高度 $(window).h ...

  10. 牛客网Java刷题知识点之子类继承不了父类里的(private属性、private方法、构造方法)

    不多说,直接上干货! 子类可以继承父类的属性和方法,除了那些private的外还有一样是子类继承不了的---构造器.对于构造器而言,它只能够被子类调用,而不能被子类继承. 调用父类的构造方法我们使用s ...