Clean C++ 12 lines code


  • 0
    X
    class Solution {
    public:
        int maxArea(vector<int>& height) {
            int left=0,right=height.size()-1,max_area=0;
            while (left<right) {
                while (left<right&&height[left]<=height[right])
                    if (max_area>=(right-left)*height[left]) left++;
                    else max_area=(right-left)*height[left]; 
                while (left<right&&height[left]>=height[right])
                    if (max_area>=(right-left)*height[right]) right--;
                    else max_area=(right-left)*height[right]; 
            }
            return max_area;
        }
    };
    

Log in to reply
 

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