leetcode-盛最多水的容器_编程题目

class Solution {
public:
    int maxArea(vector<int>& height) {
        int i = 0;
        int j = height.size()-1;
        int res = -1;
        while(i<j){
            res = max(res,min(height[j],height[i])*(j-i));
            // 每次移动短板,如果移动长板,res的值只会小于或等于上一个res
            if(height[i]<=height[j])
                i++;
            else
                j--;

        }
        return res;
    }
};