class Solution {
public:
int maxArea(vector<int>& height) {
int i=0;
int j=height.size()-1;
int S=min(height[i],height[j])*(j-i);
while(i<j){
if(height[i]>=height[j]){
j--;
}
else{
i++;
}
S=max(S,min(height[i],height[j])*(j-i));
}
return S;
}
};
网友评论