Container With Most Water
Question
None
Example 1
Input: [1,8,6,2,5,4,8,3,7]
Output: 49
Solution
- ▭
- ▯
all//Container With Most Water.py
class Solution:
def maxArea(self, height):
i, j, max_area = 0, len(height) - 1, 0
while i < j:
max_area = max(max_area, (j - i) * min(height[i], height[j]))
if height[i] < height[j]:
i += 1
else:
j -= 1
return max_area
all//Container With Most Water.py
class Solution:
def maxArea(self, height):
i, j, max_area = 0, len(height) - 1, 0
while i < j:
max_area = max(max_area, (j - i) * min(height[i], height[j]))
if height[i] < height[j]:
i += 1
else:
j -= 1
return max_area