11. 盛最多水的容器

11. 盛最多水的容器

class Solution {
    public int maxArea(int[] height) {
        if (height == null || height.length == 0) {
            return 0;
        }
        int start = 0;
        int end = height.length - 1;
        int max = 0;
        while (start < end) {
            int area = Math.min(height[start], height[end]) * (end - start);
            if (area > max) {
                max = area;
            }
            if (height[start] < height[end]) {
                start++;
            } else {
                end--;
            }
        }
        return max;
    }
}

..

原文地址:https://www.cnblogs.com/guoyu1/p/15718780.html