Skip to content

Instantly share code, notes, and snippets.

@hayunjong83
Created December 23, 2019 10:30
Show Gist options
  • Save hayunjong83/6c8bfa8b83a38d20eb09cb4a9335a5ae to your computer and use it in GitHub Desktop.
Save hayunjong83/6c8bfa8b83a38d20eb09cb4a9335a5ae to your computer and use it in GitHub Desktop.
/leetcode 11/ container with most water - brute force : O(n^2)
class Solution{
public:
int maxArea(vector<int>& height){
int max = 0;
for(int i = 0; i < height.size()-1 ; i++){
for(int j = i+1; j < height.size() ; j++){
int vertical = 0;
if(height[i] < height[j])
vertical = height[i];
else
vertical = height[j];
int area = vertical * (j-i);
if(max < area)
max = area;
}
}
return max;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment