Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9cbcc54

Browse files
feat: add container with most water
1 parent fa248c3 commit 9cbcc54

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

‎arrays_and_strings/container_with_most_water/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def max_area(height: list[int]) -> int:
2+
left = 0
3+
right = len(height) - 1
4+
max_area = 0
5+
6+
while left < right:
7+
curr_height = min(height[left], height[right])
8+
curr_width = right - left
9+
curr_area = curr_height * curr_width
10+
11+
max_area = max(curr_area, max_area)
12+
13+
if height[left] < height[right]:
14+
left += 1
15+
else:
16+
right -= 1
17+
18+
return max_area
19+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /