Skip to content

Commit e33db1c

Browse files
committed
container with most water
1 parent 09b4f02 commit e33db1c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def maxArea(self, height: List[int]) -> int:
3+
# ์‹œ๊ฐ„๋ณต์žก๋„ O(n2)์œผ๋กœ ํƒ€์ž„์•„์›ƒ
4+
# max_amount = 0
5+
# for i in range(len(height) - 1):
6+
# for j in range(i + 1, len(height)):
7+
# amount = (j-i) * min(height[i], height[j])
8+
# max_amount = max(amount, max_amount)
9+
# return max_amount
10+
11+
# ํˆฌํฌ์ธํ„ฐ ํ™œ์šฉ
12+
# ์‹œ๊ฐ„๋ณต์žก๋„ O(n)
13+
max_amount = 0
14+
left = 0
15+
right = len(height) - 1
16+
while left < right:
17+
amount = (right - left) * min(height[left], height[right])
18+
max_amount = max(amount, max_amount)
19+
if height[left] < height[right]:
20+
left += 1
21+
else:
22+
right -= 1
23+
return max_amount

0 commit comments

Comments
ย (0)