Very clean and intuitive solution accepted as best submission in C


  • 6
    //AC - 8ms;
    int maxArea(int* heights, int size)
    {
        int l=0, r=size-1;
        int max = 0;
        while(l < r)
        {
            int area = (r-l)*(heights[l] < heights[r]? heights[l++] : heights[r--]);
            max = max > area? max : area;
        }
        return max;
    }

Log in to reply
 

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