1. 程式人生 > >11. Container With Most Water C++

11. Container With Most Water C++

info col pub 技術 bubuko size area bsp alt

方法1:Brute Force(執行時間慘不忍睹,共進行)

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

技術分享圖片

11. Container With Most Water C++