File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ ์ด ๋ฌธ์ ๋ ์ฃผ์ด์ง ๋์ด ๋ฐฐ์ด์์ ๋ ๊ฐ์ ์์ง์ ์ ์ ํํด ์ต๋ ๋ฌผ์ ์์ ๊ตฌํ๋ ๋ฌธ์ ์
3+
4+ ์กฐ๊ฑด : 1) ๋ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ(๋๋น) * ๋ ์ ์ค ๋ฎ์ ๋์ด = ๋ฌผ์ ์
5+ 2) ๋ฌผ์ ๊ธฐ์ธ์ผ ์ ์์ผ๋ฏ๋ก ๋์ด๋ ๋ฎ์ ์ ๊ธฐ์ค์
6+
7+ ํด๊ฒฐ ๋ฐฉ๋ฒ :
8+ two pointers ์ ๊ทผ๋ฒ์ ์ฌ์ฉํด์
9+ ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ ํฌ์ธํฐ๋ฅผ ๋ฐฐ์ด์ ์์๊ณผ ๋์ ๋ฐฐ์นํจ
10+ ๋ ๋ฎ์ ๋์ด๋ฅผ ๊ฐ์ง ํฌ์ธํฐ๋ฅผ ์์ชฝ์ผ๋ก ์ด๋์ํค๋ฉฐ ์ต๋ ๋ฌผ์ ์์ ๊ณ์ฐํจ
11+
12+ '''
13+
14+ class Solution :
15+ def maxArea (self , height : List [int ]):
16+ # two pointers ์ด๊ธฐํ
17+ left = 0
18+ right = len (height ) - 1
19+ # ์ต๋ ๋ฌผ์ ์์ ์ ์ฅํ ๋ณ์
20+ max_water = 0
21+
22+ # ํฌ์ธํฐ๊ฐ ๊ต์ฐจํ๊ธฐ ์ ๊น์ง ๋ฐ๋ณต
23+ while left < right :
24+ # ๋ ์ ์ฌ์ด์ ๊ฑฐ๋ฆฌ ๊ณ์ฐ
25+ width = right - left
26+ # ๋ ์ ์ค ๋ฎ์ ๋์ด ๊ณ์ฐ
27+ current_height = min (height [left ], height [right ])
28+ # ํ์ฌ ๋ฌผ์ ์ ๊ณ์ฐ
29+ current_water = width * current_height
30+
31+ # ์ต๋ ๋ฌผ์ ์ ๊ณ์ฐ
32+ if current_water > max_water :
33+ max_water = current_water
34+
35+ # ๋ ๋ฎ์ ๋์ด์ ํฌ์ธํฐ ์ด๋
36+ if height [left ] < height [right ]:
37+ left += 1
38+ else :
39+ right -= 1
40+
41+ return max_water
You canโt perform that action at this time.
0 commit comments