[leetcode]11. Container With Most Water[UNSOLVED]

随手写一个循环,42testcase TLE。

从两侧向中央循环会漏条件,先放着吧。

class Solution:
    def maxArea(self, height: List[int]) -> int:
        #non-negative mean first xiangxian
        #n > 2
        lengthH = len(height)
        if lengthH == 2:
            if height[0] >= height[1]:
                return height[1]
            else:
                return height[0]
        else:
            #normal
            area = []
            for start in range(lengthH -1):
                for end in range(start +1,lengthH):
                    if height[start] >= height[end]:
                        area.append(height[end]*(end - start))
                    else:
                        area.append(height[start]*(end - start))
            return max(area)

 

posted @ 2019-05-10 10:30  夜歌乘年少  阅读(148)  评论(0编辑  收藏  举报