LeetCode-11 盛最多水的容器

  • C++
    class Solution {
    public:
        int maxArea(vector<int>& height) {
            int begin = 0;
            int end = height.size() - 1;
            int res = 0;
            while(begin!=end){
                int temp = min(height[begin], height[end]) * (end - begin);
                if(res<temp){res = temp;}
                if(height[begin]>height[end]){end--;}
                else{begin++;}
            }
            return res;
        }
    };

猜你喜欢

转载自blog.csdn.net/lolimostlovely/article/details/83240867