File tree Expand file tree Collapse file tree 1 file changed +16
-17
lines changed Expand file tree Collapse file tree 1 file changed +16
-17
lines changed Original file line number Diff line number Diff line change 33 * @param {number } k
44 * @return {number }
55 */
6- const maxResult = function ( nums , k ) {
7- const n = nums . length ;
8- const f = Array ( n ) . fill ( 0 ) ;
9- f [ 0 ] = nums [ 0 ] ;
10- const q = [ 0 ] ;
11- for ( let i = 1 ; i < n ; ++ i ) {
12- while ( i - q [ 0 ] > k ) {
13- q . shift ( ) ;
14- }
15- f [ i ] = f [ q [ 0 ] ] + nums [ i ] ;
16- while ( q . length && f [ i ] >= f [ q [ q . length - 1 ] ] ) {
17- q . pop ( ) ;
18- }
19- q . push ( i ) ;
6+ const maxResult = function ( nums , k ) {
7+ const n = nums . length
8+ const f = Array ( n ) . fill ( 0 )
9+ f [ 0 ] = nums [ 0 ]
10+ const q = [ 0 ]
11+ for ( let i = 1 ; i < n ; ++ i ) {
12+ while ( i - q [ 0 ] > k ) {
13+ q . shift ( )
2014 }
21- return f [ n - 1 ] ;
22- } ;
23-
15+ f [ i ] = f [ q [ 0 ] ] + nums [ i ]
16+ while ( q . length && f [ i ] >= f [ q [ q . length - 1 ] ] ) {
17+ q . pop ( )
18+ }
19+ q . push ( i )
20+ }
21+ return f [ n - 1 ]
22+ }
You can’t perform that action at this time.
0 commit comments