首页 > 其他 > 详细

Container With Most Water

时间:2018-01-07 17:08:32      阅读:197      评论:0      收藏:0      [点我收藏+]
class Solution(object):
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        length=len(height)
        left=0
        right=length-1
        tmp=0
        res=0
        i=0
        j=length-1
        while i<j:
            tmp=(right-left)*min(height[left],height[right])
            res=max(tmp,res)
            if(height[left]<height[right]):
                while(i<j and height[i]<=height[left]):
                    i+=1
                if(i<j):
                    left=i
            else:
                while i<j and height[j]<=height[right]:
                    j-=1
                if(i<j):
                    right=j
        return res
        
        

  

Container With Most Water

原文:https://www.cnblogs.com/xlqtlhx/p/8228288.html

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