原题链接

以Y坐标长度作为木桶边界,以X坐标差为桶底,找出可装多少水。

思路:

前后遍历。

Runtime: 5 ms, faster than 95.28% of Java

class Solution {
public int maxArea(int[] height) {
int res = 0;
int beg = 0;
int end = height.length - 1;
int temp = 0;
while (beg != end) {
temp = Math.min(height[beg], height[end]) * (end - beg);
res = temp > res ? temp : res;
if (height[beg] > height[end])
end--;
else
beg++;
}
return res;
}

[leetcode] 11. Container With Most Water (medium)的更多相关文章

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

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

  2. 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 用双指针向中间滑动,较小的高度就作为当前情 ...

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

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

  4. 蜗牛慢慢爬 LeetCode 11. Container With Most Water [Difficulty: Medium]

    题目 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai ...

  5. LeetCode 11. Container With Most Water (装最多水的容器)

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

  6. [LeetCode] 11. Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...

  7. LeetCode#11. Container With Most Water

    问题描述 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  8. Java [leetcode 11] Container With Most Water

    问题描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  9. C#解leetcode 11. Container With Most Water

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

随机推荐

  1. 通过使用URLEncoder与URLDecoder进行编码和解码

    使用改方法必须导入 java.net包 <%@page import="java.net.*" %> 编码: 当要存储或者发送数据的时候使用,将编码后的字符串再发送或者 ...

  2. Ubuntu下使用Docker搭建MySQL步骤备忘

    docker 安装和 pull MySQL镜像这里就不介绍了,很多介绍,建议去docker官方网站查看. 本文主要介绍MySQL container 运行起来之后的一些配置 在往下看之前,确保 doc ...

  3. python代码检查工具pylint 让你的python更规范

    1.pylint是什么? Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准(Pylint 默认使用的代码风格是 PEP 8,具体信息,请参阅 ...

  4. HTML连载9-video标签的第二种格式&audio标签

    一.video第二种格式 1.背景:由于视频数据非常重要,所以五大浏览器厂商都不愿意支持别人的视频格式,所以导致了没有一种视频格式是所有浏览器都支持的.这个时候W3C为了解决这个问题,所以推出了第二种 ...

  5. Redis 学习笔记(篇二):字典

    字典 字典又称为符号表.关联数组或映射(map),是一种用于保存键值对(key-value)的数据结构. 那么 C 语言中有没有这样 key-value 型的内置数据结构呢? 答案:没有. 说起键值对 ...

  6. 14 CSS权重深入

    <!-- 继承说明: (1)进行样式选择时,不指定标签的话,该选择器是继承来的. (2)继承的选择器的优先级为0,和标签选择器的优先级无可比性. --> <!DOCTYPE html ...

  7. spring与springmvc父子容器

    转载地址:http://www.tianshouzhi.com/api/tutorials/spring 1.spring和springmvc父子容器概念介绍 在spring和springmvc进行整 ...

  8. 获取Spring中的Bean

    1.Utils工具类 package com.xxx.common.helper; import org.springframework.beans.BeansException; import or ...

  9. MAC 安装telnet

    https://blog.csdn.net/licheng70356213/article/details/81162660 在10.12及以下版本,都内置了telnet命令,但是在10.13中,已经 ...

  10. Jenkins+Python+GitLab持续集成

    创建任务 登录Jenkins,点击左侧列表的新建选项.输入任务名称,选择构建一个自由风格的软件项目,点击确定. 配置 在任务配置界面,可以设置General标签中的丢弃旧的构建选项,设置保持构建的天数 ...