• + 0 comments

    This is my Java 8 solution. Feel free to ask me any questions.

    public static int jumpingOnClouds(List<Integer> c) {
        //Start jumping at index 0
        int position = 0;
        int jumps = 1;
        int n = c.size();
        
        while(position < n - 1) {
            //Examine the next two step
            
            //Jump out the clouds
            if(position + 2 >= n - 1) {
                break;
            //Move to the next to step if it's good
            } else if(c.get(position + 2) == 0) {
                position = position + 2;
            //Otherwise
            } else position++;
        
            //update jumps
            jumps++;
        }
        
        return jumps;
    }