首页 > 其他 > 详细

Container With Most Water

时间:2015-04-10 13:28:19      阅读:129      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!