leetcode_11 盛最多水的容器

题目描述

https://leetcode-cn.com/problems/container-with-most-water/description/

题解

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

猜你喜欢

转载自blog.csdn.net/Ding_xiaofei/article/details/81355425