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+ /**
2+ * @param {number[] } height
3+ * @return {number }
4+ */
5+ var maxArea = function ( height ) {
6+
7+ // 투 포인터
8+ // 왼쪽 포인터, 오른쪽 포인터. lower 라인의 포인터를 움직여야함.
9+
10+ let leftPointer = 0 ;
11+ let rightPointer = height . length - 1 ;
12+ let tempMax = 0 ;
13+
14+ while ( leftPointer !== rightPointer ) {
15+ let areaHeight = Math . min ( height [ leftPointer ] , height [ rightPointer ] ) ;
16+
17+ let areaWidth = rightPointer - leftPointer ;
18+
19+ let waterArea = areaHeight * areaWidth ;
20+
21+ tempMax = Math . max ( tempMax , waterArea ) ;
22+
23+ if ( height [ leftPointer ] < height [ rightPointer ] ) {
24+ leftPointer ++ ;
25+ } else {
26+ rightPointer -- ;
27+ }
28+ }
29+
30+ return tempMax ;
31+
32+ } ;
Original file line number Diff line number Diff line change 33 * @return {boolean }
44 */
55var isValid = function ( s ) {
6-
7- const tempArray = [ ] ;
8- const pairObject = {
6+ const bracketsObj = {
97 ')' : '(' ,
108 '}' : '{' ,
119 ']' : '['
1210 }
11+ const stackArray = [ ] ;
12+
13+ for ( let i = 0 ; i < s . length ; i ++ ) {
1314
14- for ( const ch of s ) {
15- if ( ch === '(' || ch === '{' || ch === '[' ) {
16- tempArray . push ( ch ) ;
15+ let currentBracket = s [ i ] ;
16+ let isRightBracket = currentBracket in bracketsObj ;
17+
18+ if ( ! isRightBracket ) {
19+ stackArray . push ( currentBracket ) ;
20+ continue ;
21+ }
22+
23+ let isPair = stackArray [ stackArray . length - 1 ] == bracketsObj [ currentBracket ] ;
24+
25+ if ( isPair ) {
26+ stackArray . pop ( ) ;
1727 } else {
18- if ( tempArray . pop ( ) !== pairObject [ ch ] ) {
19- return false ;
20- }
28+ return false ;
2129 }
2230 }
2331
24- return tempArray . length === 0 ;
32+ return stackArray . length === 0
33+
2534} ;
2635
2736
37+ // -----6기 활동 시의 풀이----
38+ // /**
39+ // * @param {string } s
40+ // * @return {boolean }
41+ // */
42+ // var isValid = function (s) {
43+
44+ // const tempArray = [];
45+ // const pairObject = {
46+ // ')': '(',
47+ // '}': '{',
48+ // ']': '['
49+ // }
50+
51+ // for (const ch of s) {
52+ // if (ch === '(' || ch === '{' || ch === '[') {
53+ // tempArray.push(ch);
54+ // } else {
55+ // if (tempArray.pop() !== pairObject[ch]) {
56+ // return false;
57+ // }
58+ // }
59+ // }
60+
61+ // return tempArray.length === 0;
62+ // };
63+
64+
65+
You can’t perform that action at this time.
0 commit comments