首页 > 其他 > 详细

Leetcode Array 11 Container With Most Water

时间:2017-07-25 22:20:49      阅读:341      评论:0      收藏:0      [点我收藏+]
public class Solution {
    public int maxArea(int[] height) {
        int maxa = 0;
        int maxi = 0;
        if(height.length<2)
            return 0;
        for(int i=0;i<height.length-1;i++){
            if(height[i]<height[maxi]){
                continue;                
            }
            for(int j=height.length-1;j>i;j--){
                if(height[j]>height[i]){
                    int maxmid = (j-i)*height[i];
                    maxa = maxa>maxmid?maxa:maxmid;
                    break;
                }
                else{
                    int maxmid = (j-i)*height[j];
                    maxa = maxa>maxmid?maxa:maxmid;
                }
            }
            maxi = i;
        }
        return maxa;
    }
}

 

Leetcode Array 11 Container With Most Water

原文:http://www.cnblogs.com/mxk-star/p/7236712.html

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