Skip to content

Commit 4b8828d

Browse files
committed
feat: implement maxArea function to calculate the maximum water container area
1 parent 892a5b1 commit 4b8828d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def maxArea(self, height: list[int]) -> int:
3+
# 가장 멀리 떨어져 있으면서 높이가 비슷한 막대기?
4+
max_area = 0
5+
i, j = 0, len(height) - 1
6+
while i < j:
7+
left, right = height[i], height[j]
8+
area = min(left, right) * (j - i)
9+
if area > max_area:
10+
max_area = area
11+
if left < right:
12+
i += 1
13+
else:
14+
j -= 1
15+
return max_area

0 commit comments

Comments
 (0)