File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ π 11. Container With Most Water
3+
4+ π λ¬Έμ μμ½
5+ - λμ΄ λ°°μ΄μ΄ μ£Όμ΄μ‘μ λ, λ λ§λ μ¬μ΄μ λ΄μ μ μλ λ¬Όμ μ΅λ λμ΄ κ΅¬νκΈ°
6+ - λμ΄ = min(λ λμ΄) à 거리
7+
8+ π― ν΅μ¬ μκ³ λ¦¬μ¦
9+ - ν¨ν΄: ν¬ ν¬μΈν° (Two Pointer)
10+ - μκ°λ³΅μ‘λ: O(n)
11+ - 곡κ°λ³΅μ‘λ: O(1)
12+
13+ π‘ ν΅μ¬ μμ΄λμ΄
14+ 1. μ λμμ μμ (left = 0, right = n-1)
15+ 2. νμ¬ λμ΄ κ³μ° ν μ΅λκ° κ°±μ
16+ 3. λ μμ λμ΄ μͺ½μ μ΄λ β λ ν° λμ΄λ₯Ό μ°Ύμ κ°λ₯μ±!
17+ """
18+
19+ class Solution :
20+ def maxArea (self , height : list [int ]) -> int :
21+ left , right = 0 , len (height ) - 1
22+ max_area = 0
23+
24+ while left < right :
25+ h = min (height [left ], height [right ])
26+ w = right - left
27+ max_area = max (max_area , h * w )
28+
29+ if height [left ] < height [right ]:
30+ left += 1
31+ else :
32+ right -= 1
33+
34+ return max_area
You canβt perform that action at this time.
0 commit comments