leetcode题解(六):11.Container With Most Water
Example:

Input: [1,8,6,2,5,4,8,3,7]
Output: 49

public class Solution {
    public int maxArea(int[] height) {
    	//两根指针
        int maxarea = 0, l = 0, r = height.length - 1;
        while (l < r) {
            maxarea = Math.max(maxarea, Math.min(height[l], height[r]) * (r - l));
            if (height[l] < height[r])
                l++;
            else
                r--;
        }
        return maxarea;
    }
}

相关文章: