Skip to content

Instantly share code, notes, and snippets.

@trafficinc
Created October 13, 2022 12:58
Show Gist options
  • Save trafficinc/e3d4381404ccab40a022a06c40ffca4b to your computer and use it in GitHub Desktop.
Save trafficinc/e3d4381404ccab40a022a06c40ffca4b to your computer and use it in GitHub Desktop.
Leetcode - Can Jump Game
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