Skip to content

Commit a490985

Browse files
committed
add solution: container-with-most-water
1 parent bafa98f commit a490985

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+
'''
2+
๋ฌธ์ œ: ์ปจํ…Œ์ด๋„ˆ ์ตœ๋Œ€ ๋ฌผ ๋‹ด๊ธฐ
3+
ํ’€์ด: ์–‘์ชฝ ๋์—์„œ ์‹œ์ž‘ํ•˜์—ฌ ๋” ์ž‘์€ ์ชฝ์˜ ํฌ์ธํ„ฐ๋ฅผ ์ด๋™์‹œํ‚ค๋ฉฐ ์ตœ๋Œ€ ๋„“์ด๋ฅผ ๊ณ„์‚ฐ
4+
์‹œ๊ฐ„๋ณต์žก๋„: O(n)
5+
๊ณต๊ฐ„๋ณต์žก๋„: O(1)
6+
์‚ฌ์šฉํ•œ ์ž๋ฃŒ๊ตฌ์กฐ: ํˆฌ ํฌ์ธํ„ฐ
7+
'''
8+
9+
10+
class Solution:
11+
def maxArea(self, height: List[int]) -> int:
12+
r, l = len(height)-1, 0
13+
answer = (r-l)*(min(height[r], height[l]))
14+
while r > l:
15+
answer = max(answer, (r-l)*(min(height[r], height[l])))
16+
if height[r] < height[l]:
17+
r -= 1
18+
else:
19+
l += 1
20+
return answer
21+
22+
23+

0 commit comments

Comments
ย (0)