7-line C++ O(n) Concise Solution


  • 0
    class Solution {
    public:
        int maxArea(vector<int>& height) {
            int res=0, front=0, back=height.size()-1;
            while(front<back) {
                int area=(back-front)*min(height[front],height[back]);
                res=area>res?area:res;
                height[front]<height[back]?front++:back--;
            }
            return res;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.