class Solution {
public:
int maxArea(vector<int>& height) {
int ans=0,head=0,tail=height.size()-1;
while(tail>head){
if(height[head]>height[tail]){
if((tail-head)*height[tail]>ans) ans=(tail-head)*height[tail];
--tail;
}
else{
if((tail-head)*height[head]>ans) ans=(tail-head)*height[head];
++head;
}
}
return ans;
}
};
详见力扣官方题解,题目和解法都不要紧,关键在数学证明。