File tree Expand file tree Collapse file tree
container-with-most-water
longest-increasing-subsequence 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+ let maxArea = 0 ;
7+ let left = 0 ;
8+ let right = height . length - 1 ;
9+
10+ while ( left < right ) {
11+ maxArea = Math . max ( maxArea , ( right - left ) * Math . min ( height [ left ] , height [ right ] ) ) ;
12+
13+ if ( height [ left ] < height [ right ] ) {
14+ left ++ ;
15+ } else {
16+ right -- ;
17+ }
18+ }
19+
20+ return maxArea ;
21+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {number[] } nums
3+ * @return {number }
4+ */
5+ var lengthOfLIS = function ( nums ) {
6+ const dp = new Array ( nums . length ) . fill ( 1 ) ;
7+
8+ for ( let i = 0 ; 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+ var isValid = function ( s ) {
6+ const a = [ ...s ]
7+ const stack = [ ]
8+ const mapping = { }
9+ mapping [ ')' ] = '('
10+ mapping [ ']' ] = '['
11+ mapping [ '}' ] = '{'
12+
13+ for ( let i of a ) {
14+ if ( Object . values ( mapping ) . includes ( i ) ) {
15+ stack . push ( i )
16+ } else if ( mapping . hasOwnProperty ( i ) ) {
17+ if ( ! stack . length || mapping [ i ] !== stack . pop ( ) ) {
18+ return false
19+ }
20+ }
21+ }
22+ return stack . length === 0
23+ } ;
You can’t perform that action at this time.
0 commit comments