您的位置:首页 > 编程语言 > C语言/C++

leetcode 11 in c++

2016-05-19 06:33 337 查看
My solution for leetcode #11.
class Solution {
public:
int maxArea(vector<int>& height) {
int left = 0;
int right = height.size() -1;
int maxx = 0;
int cur_area;
while(left<right){
cur_area = (right - left)*min(height.at(left),height.at(right));
if(height.at(left) < height.at(right)){
left ++;
}
else{
if(height.at(right)  < height.at(left)){
right --;

}else{
left ++;
right --;

}
}
maxx = maxx>cur_area?maxx:cur_area;

}
return maxx;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  leetcode