File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed 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+ } ;
Original file line number Diff line number Diff line change 606052|[ N-Queens II] ( ./0052-n-queens-ii.js ) |Hard|
616153|[ Maximum Subarray] ( ./0053-maximum-subarray.js ) |Easy|
626254|[ Spiral Matrix] ( ./0054-spiral-matrix.js ) |Medium|
63+ 55|[ Jump Game] ( ./0055-jump-game.js ) |Medium|
636457|[ Insert Interval] ( ./0057-insert-interval.js ) |Medium|
646558|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
656659|[ Spiral Matrix II] ( ./0059-spiral-matrix-ii.js ) |Medium|
You can’t perform that action at this time.
0 commit comments