Java 1D Array (Part 2)

  • + 1 comment

    whats wrong with my iterative approach can anyone point out?

            int n = game.length;
            int pointer = 0;
            while(pointer<=n){
                if(pointer+leap>=n || pointer+1>=n) return true;
                if(pointer+leap<n && game[pointer+leap]==0){
                    pointer+=leap;
                }
                else if(pointer+1<n && game[pointer+1]==0){
                    pointer+=1;
                }
                else if(pointer-1>=0 && game[pointer-1]==0){
                    pointer-=1;
                }
                else{
                    return false;
                }
                game[pointer]=1;
            }
            return true;