File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
container-with-most-water Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * ์๊ฐ ๋ณต์ก๋: O(n)
3
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(1)
4
+ *
5
+ * ์ต๋๋ก ๋ง์ ๋ฌผ์ ์ ์ฅํ๊ธฐ ์ํด ๊ฐ์ฅ ์ฐ์ ์ ์ผ๋ก ๊ณ ๋ คํด์ผ ํ๋ ๊ฒ์ ์งง์ ๋ง๋์ ๊ธธ์ด
6
+ * ๋ฐ๋ผ์, ์งง์ ๋์ด๋ฅผ ๊ฐ์ง๋ ์ชฝ์ ํฌ์ธํฐ๋ฅผ ์ด๋ํ๋ฉด์ ์ต๋ ์ ์ฅ ๊ฐ๋ฅํ ๊ฐ์ ๋น๊ต
7
+ *
8
+ */
9
+ class Solution {
10
+ public int maxArea (int [] height ) {
11
+ int answer = 0 ;
12
+ int left = 0 ;
13
+ int right = height .length - 1 ;
14
+
15
+ while (left < right ) {
16
+ int water = Math .min (height [left ], height [right ]) * (right - left );
17
+ answer = Math .max (answer , water );
18
+
19
+ if (height [left ] < height [right ]) {
20
+ left ++;
21
+ } else {
22
+ right --;
23
+ }
24
+ }
25
+
26
+ return answer ;
27
+ }
28
+ }
You canโt perform that action at this time.
0 commit comments