How to improve my code


  • 0
    T
        public class Solution {
        public boolean canJump(int[] A) {
        if(A.length==0) return false;
        int[] map=new int[A.length];
        return canJump(A,A.length-1,map);}
    
        public boolean canJump(int[] A, int j,int[] map) {
        if(2==map[j]) return true;
        if(1==map[j]) return false;
        
        if(j==0) return true;
        
        boolean next=false;
        for(int i=j-1;i>=0;i--){
        if((i+A[i])>=j) next=next||canJump(A,i,map);
    }
    
        if(next==true) map[j]=2;
        if(next==false) map[j]=1;
    
        return next;
        }
        }

Log in to reply
 

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