C++_22ms_79.68%


  • 2
    class Solution {
    public:
    int maxArea(vector<int>& height) {
        int i = 0, j = height.size()-1;
        int res = 0;
        while(i < j){
            int h = min(height[i], height[j]);
            res = max(res, h*(j - i));
            //The reason why it is j - i rather than j - i + 1: because   we are using the blanks to calculate the volumn rather than the points!
            while(i < j && height[i] <= h) i++;
            while(i < j && height[j] <= h) j--;
        }
        return res;
    }
    };

Log in to reply
 

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