Can someone help correct my solution ? It seems to be logically correct but results in java.lang.Stackoverflow error


  • 0
    J

    class Solution {
    public boolean canJump(int[] nums) {
    int []f = new int[1];
    f[0] =0;
    return help(nums,0,f);
    }
    public static boolean help(int[]nums,int c,int[] f)
    {
    if(c==nums.length-1)
    {
    f[0] =1;
    return true;
    }
    if(f[0]==1)
    return true;
    int val = nums[c];
    for(int i=1;i<=val;i++)
    {
    if(f[0]==1)
    return true;
    return help(nums,(c+i),f);
    }

        return false;
        
        
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.