Skip to content

Commit 352b6b5

Browse files
authored
Update 55-jump-game.js
1 parent f43bc73 commit 352b6b5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

55-jump-game.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,20 @@ const canJump = function(nums) {
1111
}
1212
return max >= nums.length - 1
1313
};
14+
15+
// another
16+
17+
/**
18+
* @param {number[]} nums
19+
* @return {boolean}
20+
*/
21+
const canJump = function(nums) {
22+
let max = 0
23+
const n = nums.length
24+
for(let i = 0; i < n; i++) {
25+
if(max < i) return false
26+
max = Math.max(max, i + nums[i])
27+
if(max >= n - 1) return true
28+
}
29+
return max >= n - 1
30+
};

0 commit comments

Comments
 (0)