Skip to content

Commit e49763b

Browse files
committed
contain most water
1 parent 82676fe commit e49763b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/contain_most_water.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def maxArea(self, height: List[int]) -> int:
6+
left, right = 0, len(height) - 1
7+
res = 0
8+
9+
while left < right:
10+
res = max(res, min(height[left], height[right]) * (right - left))
11+
if height[left] < height[right]:
12+
left += 1
13+
else:
14+
right -= 1
15+
return res

tests/test_contain_most_water.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from contain_most_water import Solution
2+
3+
testcase = [{"testcase": [1, 8, 6, 2, 5, 4, 8, 3, 7], "result": 49}]
4+
5+
6+
def test_contain_most_water():
7+
for tc in testcase:
8+
height = tc["testcase"]
9+
ans = Solution().maxArea(height)
10+
assert ans == tc["result"]

0 commit comments

Comments
 (0)