File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ var canJump = function ( nums ) {
2
+ let g = nums . length - 1
3
+ for ( let i = nums . length - 2 ; i >= 0 ; i -- ) {
4
+ if ( nums [ i ] >= g - i ) {
5
+ g = i
6
+ }
7
+ }
8
+ return ( g == 0 )
9
+ } ;
Original file line number Diff line number Diff line change
1
+ var insert = function ( intervals , newInterval ) {
2
+ intervals . push ( newInterval )
3
+ intervals . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] )
4
+ let result = [ intervals [ 0 ] ]
5
+ let [ last , curr ] = [ 0 , 0 ]
6
+ for ( let i = 1 ; i < intervals . length ; i ++ ) {
7
+ last = result [ result . length - 1 ]
8
+ curr = intervals [ i ]
9
+ if ( last [ 1 ] < curr [ 0 ] ) {
10
+ result . push ( curr )
11
+ continue
12
+ }
13
+ last [ 0 ] = Math . min ( last [ 0 ] , curr [ 0 ] ) ;
14
+ if ( last [ 1 ] <= curr [ 1 ] ) {
15
+ last [ 1 ] = Math . max ( last [ 1 ] , curr [ 1 ] ) ;
16
+ }
17
+ }
18
+ return result ;
19
+ } ;
You can’t perform that action at this time.
0 commit comments