My easy understanding cpp code


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

Log in to reply
 

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