Skip to content

Commit f8bd65d

Browse files
authored
Create 55-jump-game.js
1 parent 5f5e2df commit f8bd65d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

55-jump-game.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
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+
}
14+
}
15+
return maxIdx >= len - 1 ? true : false
16+
};

0 commit comments

Comments
 (0)