File tree Expand file tree Collapse file tree
longest-increasing-subsequence Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ const lengthOfLIS = ( nums ) => {
6+ const dp = new Array ( nums . length ) . fill ( 1 ) ;
7+
8+ for ( let i = 1 ; i < nums . length ; i ++ ) {
9+ for ( let j = 0 ; j < i ; j ++ ) {
10+ if ( nums [ j ] < nums [ i ] ) {
11+ dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;
12+ }
13+ }
14+ }
15+
16+ return Math . max ( ...dp ) ;
17+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @return {boolean }
4+ */
5+ const isValid = ( s ) => {
6+ const stack = [ ] ;
7+ const map = { ")" : "(" , "}" : "{" , "]" : "[" } ;
8+
9+ for ( const char of s ) {
10+ if ( char === "(" || char === "{" || char === "[" ) {
11+ stack . push ( char ) ;
12+ } else {
13+ if ( stack . pop ( ) !== map [ char ] ) return false ;
14+ }
15+ }
16+
17+ return stack . length === 0 ;
18+ } ;
You can’t perform that action at this time.
0 commit comments