Skip to content

Instantly share code, notes, and snippets.

@zhangxiaomu01
Created October 14, 2018 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhangxiaomu01/ac49df1bf77099369949577b40fa7c77 to your computer and use it in GitHub Desktop.
Save zhangxiaomu01/ac49df1bf77099369949577b40fa7c77 to your computer and use it in GitHub Desktop.
class Solution {
public:
int maxArea(vector<int>& height) {
int len = height.size();
int l = 0, r = len-1, maxArea = 0;
while(l<r)
{
if(height[l] <= height[r])
{
maxArea = max(maxArea, (r - l)*height[l]);
l++;
}
else
{
maxArea = max(maxArea, (r - l)*height[r]);
r--;
}
}
return maxArea;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment