Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Explanation: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
Input: height = [1,1]
Output: 1
조건
n == height.length
2 <= n <= 105
0 <= height[i] <= 104
class Solution:
def maxArea(self, height: List[int]) -> int:
l, r = 0, len(height)-1
out = 0
while l < r:
width = min(height[l], height[r])
area = width * (r - l)
out = max(out, area)
if height[l] < height[r]:
l += 1
else:
r -= 1
return out