题目
11-盛最多水的容器
https://leetcode-cn.com/problems/container-with-most-water/
题解
https://leetcode-cn.com/problems/container-with-most-water/solution/on-shuang-zhi-zhen-jie-fa-li-jie-zheng-que-xing-tu/
class Solution {
public:
int maxArea(vector<int>& height) {
int result = 0;
int area = 0;
int l = 0;
int r = height.size() - 1;
while (l < r) {
// area = min(height[l], height[r]) * (l - r);
// cout << r << endl;
// cout << l << endl;
// cout << height[r] << endl;
// cout << height[l] << endl;
area = min(height[l], height[r]) * (r - l);
result = max(result, area);
if (height[l] < height[r]) {
l++;
} else {
// r--;
r++;
}
}
return result;
}
};