
class Solution {
public:
bool canJump(vector<int>& nums) {
int maxStep = 0;
for(int i = 0; i < nums.size(); i++) {
if(i > maxStep) {
return false;
}
maxStep = max(maxStep, nums[i] + i);
}
return true;
}
};
/**
* @param {number[]} nums
* @return {boolean}
*/
var canJump = function(nums) {
let furthest = 0;
let currentJumpEnd = 0;
for(let i = 0; i < nums.length - 1; i++) {
furthest = Math.max(furthest, i + nums[i]);
if(i === currentJumpEnd) {
currentJumpEnd = furthest
}
}
return currentJumpEnd >= nums.length - 1
};
``