Container With Most Water
给一个数组, 表示一些bar的高度, 求这些bar组成的面积最大. 这个就是两个指针挨个试…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
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; } } |