Created
December 23, 2019 10:55
-
-
Save hayunjong83/853b4dfa19a9b464cfce81f858ff0df9 to your computer and use it in GitHub Desktop.
/leetcode 11/ container with most water - Two Pointer Approach : O(n)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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