```
class Solution {
public:
int maxArea(vector<int>& height) {
int left=0,right=height.size()-1,max_area=0;
while (left<right) {
while (left<right&&height[left]<=height[right])
if (max_area>=(right-left)*height[left]) left++;
else max_area=(right-left)*height[left];
while (left<right&&height[left]>=height[right])
if (max_area>=(right-left)*height[right]) right--;
else max_area=(right-left)*height[right];
}
return max_area;
}
};
```