leetcode 11.盛最多水的容器-爱代码爱编程
盛最多水的容器
思路1:双指针
- 谁小谁移动,渴望更大
class Solution {
public:
int maxArea(vector<int>& height) {
int res = -1;
int i = 0, j = height.size()-1;
while (i < j) {
res = max(res, min(height[i], height[j]) * (j - i));
height[i] <= height[j] ? ++i : --j;
}
return res;
}
}