File tree 2 files changed +59
-0
lines changed
container-with-most-water
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ์๊ฐ๋ณต์ก๋: O(n)
2
+ // ๊ณต๊ฐ๋ณต์ก๋: O(1)
3
+
4
+ /**
5
+ * @param {number[] } height
6
+ * @return {number }
7
+ */
8
+ var maxArea = function ( height ) {
9
+ let maxWater = 0 ;
10
+ let left = 0 ;
11
+ let right = height . length - 1 ;
12
+
13
+ while ( left < right ) {
14
+ const lowerHeight = Math . min ( height [ left ] , height [ right ] ) ;
15
+ const width = right - left ;
16
+ maxWater = Math . max ( maxWater , lowerHeight * width ) ;
17
+
18
+ if ( height [ left ] < height [ right ] ) {
19
+ left ++ ;
20
+ } else {
21
+ right -- ;
22
+ }
23
+ }
24
+
25
+ return maxWater ;
26
+ } ;
Original file line number Diff line number Diff line change
1
+ // ์๊ฐ๋ณต์ก๋: O(n)
2
+ // ๊ณต๊ฐ๋ณต์ก๋: O(n)
3
+
4
+ // ์คํ์ ์ฌ์ฉํ์ฌ ๊ดํธ์ ์ ํจ์ฑ์ ๊ฒ์ฌ
5
+ // ๊ดํธ๊ฐ ์ด๋ฆฌ๋ฉด ์คํ์ ์ถ๊ฐํ๊ณ ๋ซํ๋ฉด ์คํ์์ ๋ง์ง๋ง ์์๋ฅผ ๊บผ๋ด์ ์ง์ด ๋ง๋์ง ํ์ธ
6
+ // ์คํ์ด ๋น์ด์์ผ๋ฉด ์ ํจํ ๊ดํธ ๋ฌธ์์ด
7
+
8
+ /**
9
+ * @param {string } s
10
+ * @return {boolean }
11
+ */
12
+ var isValid = function ( s ) {
13
+ const bracketStack = [ ] ;
14
+ const bracketPairs = {
15
+ ')' : '(' ,
16
+ '}' : '{' ,
17
+ ']' : '['
18
+ } ;
19
+
20
+ for ( const char of s ) {
21
+ if ( char in bracketPairs ) {
22
+ const lastChar = bracketStack . pop ( ) ;
23
+
24
+ if ( lastChar !== bracketPairs [ char ] ) {
25
+ return false ;
26
+ }
27
+ } else {
28
+ bracketStack . push ( char ) ;
29
+ }
30
+ }
31
+
32
+ return bracketStack . length === 0 ;
33
+ } ;
You canโt perform that action at this time.
0 commit comments