Leetcode Container with Most Water

来源:互联网 发布:苹果电脑系统备份软件 编辑:程序博客网 时间:2024/06/05 08:15

左右夹逼,每一次都挪动较短的板子


    int maxArea(vector<int> &height) {        int i = 0, j = height.size()-1;        int maxx = 0;        int temp = 0;                   // assume no overflow        while(i < j){            if(height[i] < height[j])                temp = (j-i) * height[i++];            else                temp = (j-i) * height[j--];            maxx = max(maxx, temp);        }        return maxx;    }


0 0
原创粉丝点击