python leetcode 11. Container With Most Water

决定蓄水量大小的是左右的高度,设置left,right分别从头尾处往中心处移动,如果left处小则left右移,否则right左移

class Solution:
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        l1 = len(height)
        maxcon = 0
        p = 0 
        q = l1 - 1 
        while p < q:
            maxcon = max(maxcon, min(height[p],height[q])*(q-p))
            if height[p] < height[q]:
                p+=1
            else:
                q-=1
        return maxcon

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/84817251