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

Container With Most Water

时间:2018-01-07 17:36:12      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:div   mos   pre   body   nta   res   object   length   obj   

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

标签:div   mos   pre   body   nta   res   object   length   obj   

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

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