原题链接

以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. Qt云服务/云计算平台QTC(Qt Cloud Services)入门(0)

    在这个“大数据”的时代,传统的跨平台C++库Qt已经将魔爪丧心病狂的伸向了“云计算”.在2012年的Qt开发者大会上,Qt发布了BaaS(Backend as a Service)服务——Engini ...

  2. Ubuntu14.04 静态编译安装Qt4.8.6

    ./configure -static -nomake demos -nomake examples -nomake tools -no-exceptions -prefix /usr/local/Q ...

  3. Qt动画效果的幕后英雄:QTimeLine

    其实动画的本质就是在每一定时间间隔内显示一帧图像,当这个间隔较短的时候人眼就感觉不出来了,觉得看到的是连续的影像.Qt为开发动画效果的人员提供了一个很好的时间控制类QTimeLine. QTimeLi ...

  4. python 方法无法在线程中使用(附python获取网络流量)

    在python中,定义一个方法,直接调用可以,但是创建一个线程来调用就可能导致失败.这种现象多出现在使用com对象进行系统操作时,而且是以线程的形式调用. 异常提示如下:syntax error.WM ...

  5. ORACLE(student)表习题与答案

    因为答案都是小编自己写的,解法可能有多种,如果您觉得我的解法有误,希望您有时间给我留言. 题目:1. 查询student表中的所有记录的sname.ssex和class列. SELECT sname, ...

  6. C语言实现贪吃蛇

    日期:2018.9.11 用时:150min 项目:贪吃蛇(C语言--数组   结构体实现) 开发工具:vs2013 关键知识:数组,结构体,图形库,键位操作 源代码: #include<std ...

  7. 为什么现在这么多人开始学习Python?

    近几年Python编程语言在国内引起不小的轰动,有超越JAVA之势,本来在美国这个编程语言就是最火的,应用的非常非常的广泛,而Python的整体语言难度来讲又比JAVA简单的很多.尤其在运维的应用中非 ...

  8. 【HDU - 1010】Tempter of the Bone(dfs+剪枝)

    Tempter of the Bone 直接上中文了 Descriptions: 暑假的时候,小明和朋友去迷宫中寻宝.然而,当他拿到宝贝时,迷宫开始剧烈震动,他感到地面正在下沉,他们意识到这是一个陷阱 ...

  9. Web自动化测试 一

    Web自动化测试 一.为什么要进行web自动化测试 接口测试只能测试后端返回的数据,定位的是后端开发工程师的问题.如果前段出现了问题,我们要使用web测试去发现错误. 具体定位的问题有: 显示的数据: ...

  10. CentOS7搭建LNMP环境

    以前写的过时了,重新发一篇新的. 安装PHP 下载官网:https://www.php.net/downloads.php 为了方便,我存了现成的 百度网盘:https://pan.baidu.com ...