Share my short C++ solution


  • 1
    M

    the basic idea is to traverse the list, updating the result and keep moving the lower line.

    class Solution {
    public:
        int maxArea(vector<int> &height) {
            int i=0,j=height.size()-1,result = 0;
            while(i<j){
                result = height[i]>=height[j] ? max(result,(j-i)*height[j--]) : max(result, (j-i)*height[i++]);
            }
            return result;
        }
    };

Log in to reply
 

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