Leetcode 11. 盛最多水的容器-双指针

Leetcode 11. 盛最多水的容器-双指针

 

代码:

class Solution {
public:
    int maxArea(vector<int>& height) {
        int  L = 0,R = height.size()-1;
        int  max_Area = 0;
        while(L<R)
        {
            int ans_area = min(height[L],height[R])*(R-L);  
            max_Area = max(max_Area,ans_area);
            if(height[L]<height[R])
            {
                L++;
            }
            else{
                R--;
            }
        }
        return max_Area;

    }
};

 

上一篇:Spring boot 通用配置文件模板


下一篇:LeetCode构造矩形