Skip to content

Commit 7345f01

Browse files
committed
feat: Solve container-with-most-water problem
1 parent 8d08322 commit 7345f01

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

container-with-most-water/hu6r1s.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
class Solution:
3+
"""
4+
1. 브루트포스와 같이 전부 길이를 대조해보고 하면 시간복잡도가 터질 것.
5+
투포인터 방식을 활용하면 됨. 투포인터에 대한 문제가 코딩테스트로 많이 나올 것 같음.
6+
확실하게 공부 필요.
7+
"""
8+
def maxArea(self, height: List[int]) -> int:
9+
max_area = 0
10+
start, end = 0, len(height) - 1
11+
while start < end:
12+
area = (end - start) * min(height[start], height[end])
13+
max_area = max(area, max_area)
14+
15+
if height[start] <= height[end]:
16+
start += 1
17+
else:
18+
end -= 1
19+
20+
return max_area

0 commit comments

Comments
 (0)