[Leetcode]011. Container With Most Water

public class Solution {
public int maxArea(int[] height) {
    int left = 0, right = height.length - 1;
    int maxArea = 0;

    while (left < right) {
        maxArea = Math.max(maxArea, Math.min(height[left], height[right]) * (right - left));
        if (height[left] < height[right])
            left++;
        else
            right--;
    }

    return maxArea;
}

}
posted @ 2016-05-20 14:26  zhou23  阅读(114)  评论(0编辑  收藏  举报