首页 > 其他 > 详细

leetcode.11. Container With Most Water

时间:2019-01-08 14:15:42      阅读:137      评论:0      收藏:0      [点我收藏+]

转向c++了,底乘高,低最大,面积再想大一点就得

class Solution {
public:
    int maxArea(vector<int>& height)
    {
        int maxcon=0;
        int i=0;
        int  h;
        int j=height.size()-1;
        while(i<j)
        {
            h=min(height[i],height[j]);
           //printf("%d %d %d",h,j,i);
            maxcon=max(maxcon,h*(j-i));
            //printf("\n%d",maxcon);
            while (height[i]<=h) i++;
            while (height[j]<=h) j--;
        }
      return maxcon;
    }
};

 

保证高不断拓高,低的那一边就需要往上升到比原来高的地方才能提高容器。

leetcode.11. Container With Most Water

原文:https://www.cnblogs.com/yuhaowang/p/10238326.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!