383.Container With Most Water-装最多水的容器(中等题)
来源:互联网 发布:手机淘宝购物要需要哪 编辑:程序博客网 时间:2024/05/20 07:17
装最多水的容器
题目
给定 n 个非负整数 a1, a2, …, an, 每个数代表了坐标中的一个点 (i, ai)。画 n 条垂直线,使得 i 垂直线的两个端点分别为(i, ai)和(i, 0)。找到两条线,使得其与 x 轴共同构成一个容器,以容纳最多水。
注意事项
容器不可倾斜。样例
给出[1,3,2], 最大的储水面积是2.
题解
参看363.Trapping Rain Water-接雨水(中等题)
public class Solution { /** * @param heights: an array of integers * @return: an integer */ public int maxArea(int[] heights) { int max = 0; int left = 0; int right = heights.length-1; while (left < right) { max = Math.max(max,Math.min(heights[left],heights[right])*(right-left)); if (heights[left] < heights[right]) { left++; } else { right--; } } return max; }}
Last Update 2016.11.13
0 0
- 383.Container With Most Water-装最多水的容器(中等题)
- 383.Container With Most Water-装最多水的容器(中等题)
- Container With Most Water(能装最多水的容器)
- Container With Most Water --装最多水的容器(重)
- LeetCode OJ 之 Container With Most Water(能装最多水的容器)
- Leetcode刷题记——11. Container With Most Water(装最多水的容器)
- 6.container-with-most-water(装最多水的容器)
- Container With Most Water (容器中盛最多的水)
- 含水最多的容器(Container With Most Water)
- LeetCode | Container with most water(装最多的水)
- 11. Container With Most Water(求能装最多水的容器)
- Container With Most Water 装最多的水
- LeetCode 11. Container With Most Water(容器装水)
- Container With Most Water 求容器里能放最多的水 @LeetCode
- LeetCode11. Container With Most Water(思维题:选择左右边使得容器所盛水最多)
- Container With Most Water 盛最多的水
- Container With Most Water容器盛水
- Container With Most Water(最大容器)
- 数据结构-栈
- WordPress 伪静态规则(IIS/Apache/Nginx)
- mysql5.7.16安装或配置(啊呀,随便了.zip的那个)
- 搜索算法——六数码
- 树莓派入门--系统安装、电脑连接
- 383.Container With Most Water-装最多水的容器(中等题)
- 在使用ThinkJS搭建后台时通过时间段查询数据报错的解决方案
- 苏嵌13 16.11.12
- 代码(正三角/倒三角/水仙花)
- SAP和AD认证实践(一)
- lighttpd绑定域名
- cookies,sessionStorage 和 localStorage 的区别
- 如何实现一个标准的MD风格页面
- object