11. Container With Most Water
problem description

algorithm thought
code
algorithm analysis
Last updated

Last updated
Input: [1,8,6,2,5,4,8,3,7]
Output: 49class Solution {
public:
int maxArea(vector<int>& height) {
int i=0,j=height.size()-1;
int res=0;
while(i<j){
int h=min(height[i],height[j]);
res=max(res,h*(j-i));
while(height[i]<=h&&i<j)
++i;
while(height[j]<=h&&i<j)
--j;
}
return res;
}
};