File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 60
60
52|[ N-Queens II] ( ./0052-n-queens-ii.js ) |Hard|
61
61
53|[ Maximum Subarray] ( ./0053-maximum-subarray.js ) |Easy|
62
62
54|[ Spiral Matrix] ( ./0054-spiral-matrix.js ) |Medium|
63
+ 55|[ Jump Game] ( ./0055-jump-game.js ) |Medium|
63
64
57|[ Insert Interval] ( ./0057-insert-interval.js ) |Medium|
64
65
58|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
65
66
59|[ Spiral Matrix II] ( ./0059-spiral-matrix-ii.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 55. Jump Game
3
+ * https://leetcode.com/problems/jump-game/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array nums. You are initially positioned at the
7
+ * array's first index, and each element in the array represents your maximum
8
+ * jump length at that position.
9
+ *
10
+ * Return true if you can reach the last index, or false otherwise.
11
+ */
12
+
13
+ /**
14
+ * @param {number[] } nums
15
+ * @return {boolean }
16
+ */
17
+ var canJump = function ( nums ) {
18
+ let max = nums [ 0 ] ;
19
+
20
+ for ( let i = 1 ; i < nums . length ; i ++ ) {
21
+ if ( max < i ) {
22
+ return false ;
23
+ }
24
+ max = Math . max ( nums [ i ] + i , max ) ;
25
+ }
26
+
27
+ return true ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments