Skip to content

Commit f9398a9

Browse files
authored
Update 55-jump-game.js
1 parent 483e91f commit f9398a9

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

55-jump-game.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
* @return {boolean}
44
*/
55
const canJump = function(nums) {
6-
const len = nums.length
7-
let maxIdx = 0
8-
for(let i = 0; i < len; i++) {
9-
if (i <= maxIdx) {
10-
maxIdx = Math.max(maxIdx, i + nums[i])
11-
} else {
12-
break
13-
}
6+
let max = 0
7+
for(let i = 0, len = nums.length; i < len; i++) {
8+
if(i <= max && nums[i] > 0) {
9+
max = Math.max(max, i + nums[i])
1410
}
15-
return maxIdx >= len - 1 ? true : false
11+
}
12+
return max >= nums.length - 1
1613
};

0 commit comments

Comments
 (0)