class Solution {
public:
int maxArea(vector<int>& height) {//双指针
if(height.size()<=1) return 0;
int max_area=0;
int left = 0,right = height.size()-1;
while(left<right){
int cur_area = min(height[left],height[right])*(right-left);
max_area = max(max_area,cur_area);
if(height[left]<= height[right]) left++;
else right--;
}
return max_area;
}
};
双指针,一个在左,一个在右,当左小于右时,每次计算min(高)*横坐标间距,更新最大面积,然后将高小的那个下标前移。