题目链接:点击这里

首先我们不考虑高度的话 最大的面积应该是l r 应该是最边上的值 ,我们要取最大 所以 要维护从左到右单调增,从右到左 单调增 这样我们才能保证 面积增加

public static int maxArea(int[] height) {
        int ans = 0;
        int l = 0,r = height.length-1;
        while(l<r) {
            int h = Math.min(height[l],height[r]);
            ans = Math.max(h*(r-l), ans);
            if(height[l]<height[r]) {
                l++;
            }else {
                r--;
            }
        }

        return ans;
    }
Runtime: 2 ms, faster than 97.98% of Java online submissions for Container With Most Water.

Memory Usage: 40.7 MB, less than 15.30% of Java online submissions forContainer With Most Water
 

LeetCode--11_Container_With_Most_Water的更多相关文章

  1. 我为什么要写LeetCode的博客?

    # 增强学习成果 有一个研究成果,在学习中传授他人知识和讨论是最高效的做法,而看书则是最低效的做法(具体研究成果没找到地址).我写LeetCode博客主要目的是增强学习成果.当然,我也想出名,然而不知 ...

  2. LeetCode All in One 题目讲解汇总(持续更新中...)

    终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...

  3. [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...

  4. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  5. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  6. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  7. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  8. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  9. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  10. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

随机推荐

  1. vue学习记录③(路由)

    上篇文章我们用vue-cli脚手架工具做了个简单的hello world页面,但是我们破坏了原来的流程,而正常的访问页面应该是通过路由来实现的. 那么什么是路由呢? 路由就是通过不同的url来访问不同 ...

  2. 深挖 NPM 机制

    使用NPM安装的时候会经常出现包冲突(比如多个主模块的子模块版本不一致等),导致在开发过程中会遇到各种或大或小的问题.所有在这会介绍以下内容: NPM 主要安装方式 NPM 包信息查询 NPM 安装机 ...

  3. C# 利用位运算传递多个参数方法

    前言 在工作中用sendMessage的方法向另外一个进程中传递窗体的位置,长度,宽度四个值,但是sendMessage的方法签名中只有两个参数.于是在网上找到了一些代码,找到了这个利用位运算来合并参 ...

  4. appium+python搭建自动化测试框架_TestAPP框架(三)

    Pycharm 创建 Project,搭建 APPTEST框架如下图:   1.框架功能 业务功能的封装 测试用例封装 测试包管理 截图处理 断言处理 日志获取 测试报告生成 数据驱动 数据配置 2. ...

  5. jquery各大学选择插件

    地址:http://www.jq22.com/jquery-info5565 演示地址:http://www.jq22.com/yanshi5565

  6. linux 系统shell运行程序不退出

    如果通过ssh远程连接到linux系统终端,在shell下执行程序.假如程序名称为app,且程序本身会一直执行不退出,程序执行需要参数文件paramfile. 当我们用 ./app paramfile ...

  7. 从零开始制作 Hexo 主题

    原文地址:从零开始制作 Hexo 主题 · Ahonn 写在前面 本文将会从零开始开发一个简单的博客主题.样式主要参考 Hexo theme 中的 Noise 主题. 开始之前你需要了解: 模板引擎  ...

  8. QPen

    Help on class QPen in module PyQt5.QtGui: class QPen(sip.simplewrapper) |  QPen() |  QPen(Qt.PenStyl ...

  9. 程序员如何避免996、icu?欢迎来讨论一下。

    最近996icu火了,我以前就被996害了.现在还没缓过来,可能是自己体质比较弱吧. 以前的事就不说了,说说现在的想法吧.那么程序员如何才能避免996icu呢? 有两个基本因素: 1. 实现一个功能, ...

  10. MyIsam与InnoDB存储引擎主要区别

    MyIsam与InnoDB主要有以下4点大的区别,缓存机制,事务支持,锁定实现,数据物理存储方式(包括索引和数据). 1.缓存机制 myisam 仅仅缓存索引,不会缓存实际数据信息,他会将这一工作交给 ...