-
Notifications
You must be signed in to change notification settings - Fork 5
/
solution.py
39 lines (30 loc) · 838 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from typing import List
class Solution:
def maxArea(self, height: List[int]) -> int:
ans = 0
l, r = 0, len(height) - 1
while l < r:
ans = max(ans, min(height[l], height[r]) * (r - l))
if height[l] < height[r]:
l += 1
else:
r -= 1
return ans
class Example:
def __init__(self, height, ans):
self.height = height
self.ans = ans
def main():
examples = [
Example([1, 8, 6, 2, 5, 4, 8, 3, 7], 49),
Example([1, 1], 1),
]
solve = Solution()
for i, example in enumerate(examples):
ans = solve.maxArea(example.height)
if ans == example.ans:
print(f"PASS: CASE {i}")
else:
print(f"FAIL: CASE {i}")
if __name__ == "__main__":
main()