You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last index, or false otherwise.
my code is running for some test cases but When I submit it gets failed, need help.
class Solution {
public boolean canJump(int[] nums) {
return helper(nums, 0);
}
public boolean helper(int[] nums, int currentPointer){
if(currentPointer == nums.length - 1) {
return true;
}
boolean ans = false;
for(int i = 1; i <= nums[currentPointer]; i++) {
ans = helper(nums, currentPointer + i);
}
if(ans) return true;
return false;
}
}
nums = {1000, 1}will the code do something silly? I think it will try to access past the end of the array.