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.

Example 1:

 12 Input: [1,8,6,2,5,4,8,3,7] Output: 49 

Related Topics: ArrayTwo Pointers

## 解題邏輯與實作

 123456789101112131415161718 class Solution: def maxArea(self, height: List[int]) -> int: start = 0 end = len(height) - 1 area = 0 while(start < end): w = end - start if height[start] < height[end]: h = height[start] start += 1 else: h = height[end] end -= 1 area = max(area, h*w) return area