您的位置:首页 > 大数据 > 人工智能

Leetcode: Container With Most Water

2013-01-14 12:40 295 查看
//use two pointers: move the shorter one until they meet in the middle
class Solution {
public:
int maxArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size=height.size();
if(size<2)
return -1;
int i=0,j=size-1,temp=0,max=0;
while(i<j){
temp=(j-i)*(height[i]<height[j]?height[i]:height[j]);
max=max<temp?temp:max;
if(height[i]<height[j])
while(height[i]>height[++i]);
else
while(height[j]>height[--j]);
}
return max;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: