-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.py
31 lines (23 loc) · 836 Bytes
/
11.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
# leetcode problem no. 11(Medium )
# # Brute Force approach
# class Solution:
# def maxArea(self, height: List[int]) -> int:
# result = 0
# for left in range(len(height)):
# for right in range(len(height)):
# area = (right - left) * min(height[left], height[right])
# result = max(result, area)
# return result
# Optimized approach
class Solution:
def maxArea(self, height: List[int]) -> int:
result = 0
left, right = 0, len(height) - 1
while left < right:
area = (right - left) * min(height[left], height[right])
result = max(result, area)
if height[left] < height[right]:
left += 1
else:
right -= 1
return result