Leetcode 11. Container With Most Water (Medium) (cpp)
来源:互联网 发布:知福茶叶怎么样 编辑:程序博客网 时间:2024/06/06 02:43
Leetcode 11. Container With Most Water (Medium) (cpp)
Tag: Array, Two Pointers
Difficulty: Medium
/*11. Container With Most Water (Medium)Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: You may not slant the container.*/class Solution {public:int maxArea(vector<int>& height) {int water = 0, i = 0, j = height.size() - 1;while (i < j) {int h_min = min(height[i], height[j]);water = max(water, h_min * (j - i));while (height[j] <= h_min && i < j) { j--; } while (height[i] <= h_min && i < j) { i++; } } return water; }};
0 0
- Leetcode 11. Container With Most Water (Medium) (cpp)
- [Leetcode 11, Medium] Container With Most Water
- Leetcode 11. Container With Most Water (Medium) (java)
- 【LeetCode】11.Container With Most Water(Medium)解题报告
- 11. Container With Most Water Medium
- 11. Container With Most Water Medium
- [LeetCode] 011. Container With Most Water (Medium) (C++/Java/Python)
- LeetCode-11-Container With Most Water(证明)-Medium
- LeetCode 11. Container With Most Water
- [LeetCode]11.Container With Most Water
- LeetCode --- 11. Container With Most Water
- LeetCode 11.Container With Most Water
- [Leetcode] 11. Container With Most Water
- [leetcode] 11.Container With Most Water
- 【leetcode】11. Container With Most Water
- [LeetCode]11. Container With Most Water
- 11. Container With Most Water LeetCode
- leetcode 11. Container With Most Water
- 解决GridLayout API level小于21时平均分配行列的问题
- 7. Reverse Integer
- 重拾英语
- Jemeter执行顺序
- [区间DP]乘积最大
- Leetcode 11. Container With Most Water (Medium) (cpp)
- Android开发实现中的“再按一次返回键退出程序”
- Java 设计模式之桥接模式的详解(结构模式)
- WEB前端之路径问题
- Model和jstl
- 2016夏季练习——7月结束
- 杭电5363Key Set
- ImageLoader获取bitmap对象
- 【English】it has been three months