Skip to content

Commit 174a7e1

Browse files
committed
feat: week6 문제풀이 (242)
1 parent 6f45048 commit 174a7e1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

container-with-most-water/jinah92.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# O(1) spaces, O(N) times
2+
class Solution:
3+
def maxArea(self, height: List[int]) -> int:
4+
max_area = 0
5+
start, end = 0, len(height)-1
6+
7+
while start != end:
8+
# start, end 포인터에서 물의 넓이 계산 및 최대값 계산
9+
max_area = max((end-start)*min(height[start], height[end]), max_area)
10+
if height[start] < height[end]:
11+
start += 1
12+
elif height[start] >= height[end]:
13+
end -= 1
14+
15+
return max_area

0 commit comments

Comments
 (0)