Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 748 Bytes

11.-container-with-most-water.md

File metadata and controls

25 lines (21 loc) · 748 Bytes

11. Container With Most Water

class Solution:
    def maxArea(self, height: List[int]) -> int:
        ## 维护一个窗口,总有种强文出的题,看啥都能sliding windows 一下
        ## 点开发现也没错,双指针
        ## 控制一个变量..间距
        ## 然后确定更新指针的情况
        ans = 0
        l, r = 0, len(height)-1
        while l < r:
            if height[l] < height[r]:
                ans = max(ans,self.getArea(height,l, r))
                l += 1
            else:
                ans = max(ans,self.getArea(height,l, r))
                r -= 1
            
        return ans
            
    def getArea(self,height,l,r):
        return  min(height[l],height[r])*(r - l)