Skip to content

Commit 6b99200

Browse files
committed
[LeetCode Sync] Runtime - 111 ms (21.31%), Memory - 28.5 MB (68.25%)
1 parent 0ee07e9 commit 6b99200

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def maxArea(self, height: List[int]) -> int:
3+
res = 0
4+
l, r = 0, len(height) - 1
5+
6+
while l < r:
7+
# AREA = L * B where
8+
# L = length of container (r-l) Index.
9+
# B = the most minimum height from both sides of the container.
10+
temp = (r-l) * min(height[l], height[r])
11+
res = max(res,temp)
12+
13+
# proceed while keeping the maximum height.
14+
# for example, if left tower is higher than the right,
15+
# then calculate area for the next right tower (r--)
16+
17+
if height[l] > height[r]:
18+
r -= 1
19+
else:
20+
l += 1
21+
22+
return res

0 commit comments

Comments
 (0)