码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode.11. Container With Most Water

时间:2019-01-08 15:25:36      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:contain   ret   color   while   most   nta   pre   tor   max   

转向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

标签:contain   ret   color   while   most   nta   pre   tor   max   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!