class Solution {
public:
int min(int a, int b){
if (a < b) {
return a;
} else {
return b;
}
}
int max(int a, int b){
if (a > b) {
return a;
} else {
return b;
}
}
int maxArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int left = 0, right = height.size() - 1;
int maxarea;
maxarea = (right-left)*min(height[left], height[right]);
while(left < right) {
if (height[left] < height[right]) {
left++;
} else {
right--;
}
maxarea = max(maxarea,
(right-left)*min(height[left], height[right]));
}
return maxarea;
}
};
Container With Most Water
最新推荐文章于 2019-11-06 10:22:53 发布