leetcode Container With Most Water

Container With Most Water

Total Accepted: 2685 Total Submissions: 9008

Given n non-negative integers a1a2, ..., an, where each represents a point at coordinate (iai). n vertical lines are drawn such that the two endpoints of line i is at (iai) 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.

This problem is different from largest rectangle in histogram. It's just a line instead of a histogram. So there is no water.

class Solution {
public:
int maxArea(vector<int> &height) {
int size = height.size(), l = 0, r = size - 1, res = 0;
if (size == 0)
return 0;
while (l < r) {
if (res < (r - l)*min(height[l],height[r]))
res = (r - l)*min(height[l],height[r]);
if (height[l] <= height[r])
++l;
else
--r;
}
return res;
}
};

【LeetCode】Container With Most Water 解题报告

2014-12-02 09:24:29

[LeetCode][11]Container With Most Water解析 时间复杂度为O(n) -Java实现

2016-06-12 14:16:19

LeetCode --- 11. Container With Most Water

2015-01-29 10:49:05

[LeetCode]Container With Most Water, 解题报告

2013-12-10 19:47:10

LeetCode(11) ContainerWithMostWater

2013-12-09 08:23:48

【LEETCODE】11-Container With Most Water [Python]

2016-01-07 09:03:13

LeetCode 11 Container With Most Water (C,C++,Java,Python)

2015-05-07 22:56:04

[LeetCode] 011. Container With Most Water (Medium) (C++/Java/Python)

2015-03-02 22:51:59

[C++]LeetCode: 39 Container With Most Water

2014-12-02 13:31:50

【LeetCode-面试算法经典-Java实现】【011-ContainerWithMostWater（容纳最多的水）】

2015-07-19 06:58:05