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

Container With Most Water

时间:2015-04-10 13:30:50      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:

    public int maxArea(int[] height) {
        //http://blog.csdn.net/linhuanmars/article/details/21145429 贪心算法要看看
        if(height==null || height.length<2) return 0;
        int max = 0;
        int l=0, h = height.length-1;
        while(l<h){
            max = Math.max(max,Math.min(height[l], height[h])*(h-l));
            if(height[l]<height[h]){
                l++;
            }else{
                h--;
            }
        }
        return max;
        
    }

 

Container With Most Water

标签:

原文地址:http://www.cnblogs.com/jiajiaxingxing/p/4414215.html

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