File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed
best-time-to-buy-and-sell-stock
container-with-most-water Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } prices
3+ * @return {number }
4+ */
5+ var maxProfit = function ( prices ) {
6+ // 가장 작은 수
7+ let minNum = prices [ 0 ] ;
8+ // 차이 값
9+ let maxProfit = 0 ;
10+ for ( let i = 1 ; i < prices . length ; i ++ ) {
11+ minNum = Math . min ( minNum , prices [ i - 1 ] ) ; // 이전꺼 중 가장 작은 수
12+ maxProfit = Math . max ( maxProfit , prices [ i ] - minNum ) ;
13+ }
14+ return maxProfit ;
15+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } height
3+ * @return {number }
4+ */
5+ const maxArea = function ( height ) {
6+ let left = 0 ;
7+ let right = height . length - 1 ;
8+ let max = 0 ;
9+
10+ while ( left < right ) {
11+ const graphW = right - left ;
12+ const grapghH = Math . min ( height [ left ] , height [ right ] ) ;
13+
14+ max = Math . max ( max , graphW * grapghH ) ;
15+
16+ if ( height [ left ] <= height [ right ] ) {
17+ left ++ ;
18+ } else {
19+ right -- ;
20+ }
21+ }
22+
23+ return max ;
24+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @return {boolean }
4+ */
5+ var isValid = function ( s ) {
6+ const newArr = [ ...s ] ;
7+ if ( newArr [ 0 ] === ")" || newArr [ 0 ] === "}" || newArr [ 0 ] === "]" ) {
8+ return false ;
9+ }
10+
11+ for ( let i = 1 ; i < newArr . length ; i ++ ) {
12+ if ( newArr [ i ] === ")" && newArr [ i - 1 ] === "(" ) {
13+ newArr . splice ( i - 1 , 2 ) ;
14+ i = i - 2 ;
15+ }
16+
17+ if ( newArr [ i ] === "}" && newArr [ i - 1 ] === "{" ) {
18+ newArr . splice ( i - 1 , 2 ) ;
19+ i = i - 2 ;
20+ }
21+
22+ if ( newArr [ i ] === "]" && newArr [ i - 1 ] === "[" ) {
23+ newArr . splice ( i - 1 , 2 ) ;
24+ i = i - 2 ;
25+ }
26+ }
27+ return newArr . length === 0 ? true : false ;
28+ } ;
You can’t perform that action at this time.
0 commit comments