题目描述

在这里插入图片描述
在这里插入图片描述

题解

思路:两个边界哪个小,收缩哪个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
int maxArea(vector<int>& height) {
int left = 0;
int right = height.size() - 1;
int maxarea = 0;
while(left < right)
{
int cur_area = min(height[left], height[right]) * (right - left);
maxarea = max(maxarea, cur_area);
height[left] < height[right] ? ++left : --right;
}
return maxarea;
}
};

在这里插入图片描述