Commit e972cfe3 authored by yaozc's avatar yaozc
Browse files

keep going!

parent d91ee0dc
......@@ -48,8 +48,29 @@ public:
// 4. container with most water
// 从最左和左右开始,在最wide的情况下计算出water的值
// 然后依次判断左右高低,高的保留,低的跳过,左右筛选后再计算water值,直到最后计算出最大water
class Solution {
public:
int maxArea(vector<int>& height) {
int left = 0;
int right = height.size() -1;
int water = 0;
while(left < right){
water = max(water, ((right - left) * min(height[left], height[right])));
if(height[left] < height[right]){
left++;
}
else{
right--;
}
}
return water;
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment