Created
October 13, 2022 12:58
-
-
Save trafficinc/e3d4381404ccab40a022a06c40ffca4b to your computer and use it in GitHub Desktop.
Leetcode - Can Jump Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canJump = function(nums) { | |
let len = nums.length; | |
let max = 0; | |
for (let i = 0; i < len; i++) { | |
if (i > max) return false; | |
max = Math.max(max, i + nums[i]); | |
} | |
return true; | |
}; | |
console.log(canJump([2,3,1,1,4])); // true | |
console.log(canJump([3,2,1,0,4])); // false | |
console.log(canJump([2,3,1,1,4])); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment