Skip to content

Instantly share code, notes, and snippets.

@hyfrey
Created September 17, 2012 14:20
Show Gist options
  • Save hyfrey/3737593 to your computer and use it in GitHub Desktop.
Save hyfrey/3737593 to your computer and use it in GitHub Desktop.
leetcode: Container With Most Water
class Solution {
public:
int max(int a, int b) {
return a > b ? a : b;
}
int min(int a, int b) {
return a < b ? a : b;
}
int maxArea(vector<int> &height) {
int i = 0;
int j = height.size() - 1;
int max_area = 0;
while (i < j) {
int area = min(height[i], height[j]) * (j - i);
max_area = max(max_area, area);
if (height[i] < height[j]) {
i++;
} else {
j--;
}
}
return max_area;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment