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;
    }
}

..

posted @ 2021-12-22 11:29  guoyu1  阅读(26)  评论(0编辑  收藏  举报