11. 盛最多水的容器
思路:双指针,每次将高度最低的那一边进行更新,因为储水的容量不光是和长度有关,还和高度的下线有关,所以我们贪心的保留最高的一边,而去更新最低的一边。
class Solution {
public:
int maxArea(vector<int>& height) {
int l=0,r=height.size()-1;
int maxx=0;
while(l<r){
maxx=max(maxx,(r-l)*min(height[l],height[r]));
if(height[l]<height[r]) l++;
else r--;
}
return maxx;
}
};