Leetcode 11: Container With Most Water

class Solution:
    def maxArea(self, height):
        if len(height)==2:
            return min(height[0], height[1])
        lf=0
        rg=len(height)-1
        max_area=0
        for i in range(len(height)-1):
            shorter_line = min(height[lf], height[rg])
            temp = shorter_line * (rg - lf)
            if temp > max_area:
                max_area = temp
            if shorter_line == height[lf]:
                lf += 1
            else:
                rg -= 1 
        return max_area

 

上一篇:11-散列1 电话聊天狂人 (25 分)


下一篇:CMP71001 Risk assessment