Container With Most Water
给一个数组, 表示一些bar的高度, 求这些bar组成的面积最大. 这个就是两个指针挨个试…
public class Solution {
public int maxArea(int[] height) {
int left = 0;
int right = height.length - 1;
int max = Integer.MIN_VALUE;
while(left < right) {
max = Math.max(max,(right - left) * Math.min(height[left],height[right]));
if(height[left] < height[right])
left ++;
else
right --;
}
return max;
}
}