题目链接:点击这里

首先我们不考虑高度的话 最大的面积应该是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. .net面向对象设计原则

    稳定的框架来源于好的设计,好的设计才能出好的作品,掌握面向对象基本原则才会使我们的设计灵活.合理.不僵化,今天就来谈一谈我们.net 面向对象设计的基本原则. 对于一个没有任何设计经验的开发者来说,如 ...

  2. thinkPHP5.0 URL路由优化

    在tp中访问页面的时候URL地址是 域名/模块/控制器/方法,在点击首页的时候URL是 域名/index/index/index 而不是只显示域名,这样不利于SEO,而且强迫症的我看着很不爽,这个时候 ...

  3. PDF转图片工具

    点击下载( 提取码:1ll1 ) 软件功能基于mupdf,UI使用wxpython开发 功能: 支持pdf转图片,图片格式png 支持批量转换 使用: 第一步,点击按钮添加文档到列表,或直接将待转换文 ...

  4. Android 使用TextView实现跑马灯效果

    前言 我们在开发中经常会遇到一个小问题.比如下面一个小例子: 这个文字太长,单行中导致无法全部显示出来,这就是今天要实现的功能. 当然,百度中也有很多这种解决方案. 其中有一种,例如: <Tex ...

  5. ES入门REST API

    在ES中存在4种数据对象,分别是 index  ,  type ,  document  , field .   其跟我们熟悉的关系型数据库得二维表得对应关系为: index -> table表 ...

  6. MySQL数据库在IO性能优化方面的设置选择(硬件)

    提起MySQL数据库在硬件方面的优化无非是CPU.内存和IO.下面我们着重梳理一下关于磁盘I/O方面的优化. 1.磁盘冗余阵列RAID RAID(Redundant Array of Inexpens ...

  7. Django-1- urls的路由配置, 命名, 重定向, path及re_path

    1-项目目录下配置(path方法) 这里的访问路径可以是127.0.0.1:8000/index/      2-APP目录下配置(path方法) 这里的访问路径可以是127.0.0.1:8000/t ...

  8. 如何学好java

    今天发现这么一篇文章,对于笔者谈的:"一方面很努力学习,一方面又觉得不踏实",我感同身受.觉得文章写得不错,在此献给一些在java中努力的朋友们,希望能有所收获. 文章原内容: 近 ...

  9. Win7/Win8.1升级Win10后屏幕一直闪烁怎么办?

    有些用户在把Win7/Win8.1升级到Win10正式版后,发现屏幕一直不停闪烁,以至于无法正常使用.出现这种情况的原因可能有很多,微软社区的论坛审阅人Alex_Shen给出了一种解决方案:进入安全模 ...

  10. 使用bootstrap的dropdown部件时报错:error:Bootstrap dropdown require Popper.js

    前言:前端小白一枚,刚注册博客,先发个学习过程中新碰到小问题试试水吧~ 摘要:最近在学习bootstrap,偶然碰到了一个小问题,bootstrap网站也没有做过多的解释,今天分享给大家. 问题描述: ...