Scan from two ends to the middle, Area = (j-i)*min(a_i, a_j).
class Solution {
public:
int maxArea(vector<int> &height) {
int i=0;
int maxA=0;
int j=height.size()-1;
while(i<j) {
int tmpA=min(height[i],height[j])*(j-i);
maxA=max(maxA, tmpA);
if(height[i]<height[j]) i++;
else j--;
}
return maxA;
}
};