题目描述
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/eb779391f2c9ac7f78368d94a866d2a6.png)
思路
用双指针法。
每次向内移动较短的那个板,能带来更大的效益。
代码
class Solution {
public int maxArea(int[] height) {
int res = 0;
int i = 0,j = height.length - 1;
while(i < j){
res = height[i] < height[j] ?
Math.max((j - i) * height[i++],res)
: Math.max((j - i) * height[j--],res);
}
return res;
}
}