[leetcode] 11. Container With Most Water (medium)
以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)的更多相关文章
- Leetcode 11. Container With Most Water(逼近法)
11. Container With Most Water Medium Given n non-negative integers a1, a2, ..., an , where each repr ...
- 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 用双指针向中间滑动,较小的高度就作为当前情 ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- 蜗牛慢慢爬 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 ...
- LeetCode 11. Container With Most Water (装最多水的容器)
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- [LeetCode] 11. Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). ...
- LeetCode#11. Container With Most Water
问题描述 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- Java [leetcode 11] Container With Most Water
问题描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- C#解leetcode 11. Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
随机推荐
- BuildWinRTL.dproj 用这个重新编译就行
BuildWinRTL.dproj 用这个重新编译就行 我每次安装新版本,都删掉了这两个函数 {$IFDEF DEBUG}exports dbkFCallWrapperAddr,{$IF defin ...
- SpringMVC使用MultipartFile文件上传,多文件上传,带参数上传
一.配置SpringMVC 二.单文件与多文件上传 三.多文件上传 四.带参数上传 一.配置SpringMVC 在spring.xml中配置: <!-- springmvc文件上传需要配置的节点 ...
- nginx(一) nginx详解
nginx是一个被广泛使用的集群架构组件,我们有必要对它有足够的了解.下面将先认识nginx:包括应用场景.nginx基本架构.功能特性.并发模型以及配置说明,最后我们再总结下,为什么选择nginx的 ...
- Spring特点
1.非侵入式所谓非侵入式是指,Spring框架的API不会在业务逻辑上出现,即业务逻辑是POJO(Plain Old Java Objects).由于业务逻辑中没有Spring的API,所以业务逻辑可 ...
- URL收集
window下 php5.5 安装pthread扩展:http://blog.csdn.net/aoyoo111/article/details/19020161
- Android前沿技术
一.热升级Tinker源码解析与手写二.热修复阿里百川Sophix内核原理三.App Instantgoogle8.0 类似热更新技术原理与实战四.强制更新1.银行应用非对称加密对称加密五.组件化框架 ...
- JSON对象和JavaScript对象直接量的区别--不同之处
JSON对象和JS对象直接量 在工作当中,我们总是可以听到人说将数据转换为JSON对象,或者说把JSON对象转换为字符串之类的话,下面是关于JSON的具体说明. JSON对象并不是JavaScript ...
- ABP开发框架前后端开发系列---(13)高级查询功能及界面的处理
在一般的检索界面中,基于界面易用和美观方便的考虑,我们往往只提供一些常用的条件查询进行列表数据的查询,但是有时候一些业务表字段很多,一些不常见的条件可能在某些场景下也需要用到.因此我们在通用的查询条件 ...
- phpstorm+xdebug手机app调试
1.安装过程网上搜一下全都是,这里省略. 2.由于debug调试需要去判断cookie中XDEBUG_SESSION,然后去调试.由于app接口请求没法去传,而且就算去传递也很麻烦,还要让app去改动 ...
- 找不到’geckodriver’ 的环境path问题“ Message: 'geckodriver' executable needs to be in PATH. ”
运行测试脚本报找不到’geckodriver’ 的环境path 的错误 selenium3.x webdriver/firefox/webdriver.py的init中,executable_pat ...