We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 95d9c8a commit 870556dCopy full SHA for 870556d
container-with-most-water/Seoya0512.py
@@ -0,0 +1,25 @@
1
+'''
2
+이중 For-loop을 사용하면 시간복잡도가 O(n^2)이 되므로 시간초과가 발생
3
+리트코드의 Hint를 참고해 Two Pointer를 사용하는 방식으로 시도했습니다.
4
+
5
+Time Complexity: O(n)
6
+- While 루프를 사용해서 인덱스 i와 j가 만날 때까지 반복으로 진행하기에 O(n)
7
8
+Space Complexity: O(1)
9
+- height 값과, max_area 값 모두 상수 공간을 사용
10
11
+class Solution:
12
+ def maxArea(self, height: List[int]) -> int:
13
+ i, j = 0, len(height) - 1
14
+ max_area = 0
15
16
+ while i < j:
17
+ area = min(height[i], height[j]) * (j-i)
18
+ max_area = max(area, max_area)
19
20
+ if height[i] < height[j]:
21
+ i += 1
22
+ else:
23
+ j -= 1
24
25
+ return max_area
0 commit comments