LeetCode之盛水最多的容器

1. 题目描述

https://leetcode-cn.com/problems/container-with-most-water

2. 示例代码

双指针法

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;
    }
}
发布了306 篇原创文章 · 获赞 46 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/kaikai_sk/article/details/93043219