Given/n/non-negative integers/a//1/,/a//2/, …,/a//n/, where each represents a point at coordinate (/i/,/a//i/)./n/vertical lines are drawn such that the two endpoints of line/i/is at (/i/,/a//i/) and (/i/, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note:You may not slant the container and/n/is at least 2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
class(object): defmaxArea(self, height): """ :type height: List[int] :rtype: int """ max_area = 0 l, r = 0, len(height) - 1 while l < r: area = 0 if height[l] > height[r]: area = (r-l)*height[r] r -= 1 else: area = (r-l)*height[l] l += 1 max_area = max(area, max_area) return max_area
近期评论