给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。
找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。返回容器可以储存的最大水量。

public class Test {
public static void main(String[] args) {
int[] a = {1, 8, 6, 2, 5, 4, 8, 3, 7};
System.out.println(maxArea(a));
}
public static int maxArea(int[] height) {
//入参校验
//最大面积
int maxArea = 0;
//右指针
int right = height.length - 1;
//左指针
int left = 0;
while (left < right) {
int tempArea = height[left] < height[right] ?
(right - left) * height[left++] :
(right - left) * height[right--];
maxArea = Math.max(maxArea, tempArea);
}
return maxArea;
}
}

题目来源:盛最多水的容器