class Solution {
public:
int maxArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int start = 0;
int end = height.size() - 1;
int water = 0;
while (start < end) {
water = max(water, min(height[start], height[end]) * (end - start));
if (height[start] < height[end]) {
start++;
}
else {
end--;
}
}
return water;
}
};
LeetCode Container With Most Water
最新推荐文章于 2013-04-05 14:46:28 发布