http://oj.leetcode.com/problems/container-with-most-water/
// It's not easy to get the O(N) solution directly.
// The idea is to use this conclusion: if(height[i]<height[j]) then MaxArea(i,j)>=MaxArea(i+1,j)>=MaxArea(i,j-1), and vice versa
class Solution {
public:
int maxArea(vector<int> &height) {
int res=0;
int left=0, right=height.size()-1;
while(left<right){
res=max(res,min(height[left],height[right])*(right-left));
if(height[left]<height[right]) left++;
else right--;
}
return res;
}
};