class Solution {
public:
int maxArea(vector<int>& height) {
int right = height.size()-1,left = 0;
int ans = 0,help;
while(left < right){
help = min(height[right],height[left]) * (right - left);
ans = max(help,ans);
if(height[right] > height[left])
left++;
else right--;
}
return ans;
}
};
采用双指针的方法,从两边向中间靠拢。
但是一旦向中间靠拢宽度一定会变小,所以尽量保留长度较大的那一边