Skip to content

Instantly share code, notes, and snippets.

@hayunjong83
Created December 23, 2019 10:55
Show Gist options
  • Save hayunjong83/853b4dfa19a9b464cfce81f858ff0df9 to your computer and use it in GitHub Desktop.
Save hayunjong83/853b4dfa19a9b464cfce81f858ff0df9 to your computer and use it in GitHub Desktop.
/leetcode 11/ container with most water - Two Pointer Approach : O(n)
class Solution{
public:
int maxArea(verctor<int>& height){
int max = 0;
int left = 0, right = height.size()-1;
while(left < right){
max = std::max( max, std::min(height[left], height[right]) * (right - left));
if(height[left] < height[right])
left++;
else
right--;
}
return max;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment