[LeetCode]Container With Most Water
来源:互联网 发布:java 模块化开发 编辑:程序博客网 时间:2024/06/14 14:06
解题思路:
1,两条线之间的盛水量,由x坐标之 差与height较低的那个y来决定;
2,拿第1条和最后1条线来看,这个容器有最大的宽度。所以,如果还存在容量更大的容器,那么它的2条线一定比边上的两条线要高。
所以可以得到如下代码:
class Solution {public: int maxArea(vector<int>& height) { int i = 0; int j = height.size()-1; int maxWater = 0; while(i < j){ int h = min(height[i], height[j]); maxWater = max(maxWater, h * (j - i)); while(height[j] <= h && i < j) j--; while(height[i] <= h && i < j) i++; } return maxWater; }};
0 0
- [LeetCode]Container With Most Water
- LeetCode: Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode Container With Most Water
- LeetCode: Container With Most Water
- [Leetcode] Container With Most Water
- Leetcode: Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode Container With Most Water
- [Leetcode] Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode-Container With Most Water
- Container With Most Water leetcode
- LeetCode - Container With Most Water
- LeetCode: Container With Most Water
- Leetcode: Container With Most Water
- 【LeetCode】Container With Most Water
- Leetcode: Container With Most Water
- SVN checkout造成桌面图标显示问号解决办法
- 对一个现成的ts进行pat和pmt表的解析,并提取视频保存到文件中
- Generate Parentheses
- webbench压力测试工具
- 复习三:大数据&分布式
- [LeetCode]Container With Most Water
- [leetcode-]Remove Nth Node From End of List(C)
- 一个程序演示所有的shell编程知识
- Revit 二次开发之安装包的制作
- 不借助第三个变量实现两个变量交换的思考
- Android 实现动态体温计
- JAVA的比较之==
- FBReader 最新源码编译(Windows环境)和研究(一)
- __sync_val_compare_and_swap, 无锁锁