题目:
分析:
1、双指针,储水为(R-L )* 二者较小高度,如题目,(9-2)* 7 = 49
2、双指针向中间靠,每次移动较矮的指针。
代码:
public int maxArea(int[] height) {int left = 0;int right = height.length - 1;int max = 0;while (left < right) {if (height[right] > height[left]) {max = Math.max(max, (right - left) * height[left]);left++;} else {max = Math.max(max, (right - left) * height[right]);right--;}}return max;}