Share my easy understand C++ BF


  • 0
    class Solution {
    public:
        int maxArea(vector<int>& height) {
            int maxArea = 0, minLeft = 0, minRight = 0;
            for(int i = height.size() - 1; i >= 0; i--){
                if(height[i] < minRight) continue;
                minLeft = 0;
                for(int j = 0; j < i; j++){
                    if(height[j] < minLeft) continue;
                    maxArea = max(maxArea, min(height[i], height[j]) * (i - j));
                    minLeft = max(minLeft, height[j]);
                }
                minRight = max(minRight, height[i]);
            }
            return maxArea;
        }
    };
    

Log in to reply
 

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