首页 > 代码库 > LeetCode Container With Most Water

LeetCode Container With Most Water

class Solution{
    public:
        int maxArea(vector<int>& height) {  
        int len = height.size(), low = 0, high = len -1 ;  
        int maxArea = 0;  
        while (low < high) {  
            maxArea = max(maxArea, (high - low) * min(height[low], height[high]));  
            if (height[low] < height[high]) {  
                low++;  
            } else {  
                high--;  
            }  
        }  
        return maxArea;  
    }
};

应该算是贪婪算法吧,直接从disscus里抄了,自己只能想出一个nlogn的,对贪婪没什么感觉,想不到