File tree Expand file tree Collapse file tree
container-with-most-water Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution :
2+ def maxArea (self , height : List [int ]) -> int :
3+ '''
4+ 1.๋ฌธ์ : ๊ฐ์ฅ ๋ง์ ์์ ๋ฌผ์ ์ ์ฅํ ์ ์๋ max value return
5+ 2.์กฐ๊ฑด
6+ - n: ๋์ด๋ฅผ ์๋ฏธ, ์ต์ = 5, ์ต๋ = 10^5
7+ - ์์๊ฐ ์ต์ = 0, ์ต๋ = 10^4
8+ 3.ํ์ด
9+ - ๋์ด๋ height[i], height[j] ์ค์ ์์ ๊ฐ, ๊ฐ๋ก๋ abs(i-j)
10+ - output = ๋์ด x ๊ฐ๋ก
11+ -> 2์ค loop ๋ O(n^2) ๋ก TLE ๋ฐ์.
12+ -> two pointer ๋ก O(n) ์ผ๋ก ํด๊ฒฐ!
13+ '''
14+
15+ n = len (height )
16+ maxArea = 0
17+
18+ left = 0
19+ right = n - 1
20+
21+ while left < right :
22+ curArea = abs (right - left ) * min (height [left ], height [right ])
23+ maxArea = max (curArea , maxArea )
24+
25+ #height ์ด ๋ฎ์์ชฝ pointer update
26+ if height [left ] < height [right ]:
27+ left += 1
28+ else :
29+ right -= 1
30+
31+ return maxArea
32+
You canโt perform that action at this time.
0 commit comments