Created
December 23, 2019 10:30
-
-
Save hayunjong83/6c8bfa8b83a38d20eb09cb4a9335a5ae to your computer and use it in GitHub Desktop.
/leetcode 11/ container with most water - brute force : O(n^2)
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(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