题目描述

思路
用双指针法。
每次向内移动较短的那个板,能带来更大的效益。
代码
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;
}
}