• + 0 comments

    Java Simpler Solution

    public static int jumpingOnClouds(List<Integer> c) {
        int jumps = 0;
        jumps += c.size() == 2 ? 1 : 0;
        for(int i = 2; i < c.size(); i+=2){
            if(c.get(i) == 1){
                i -= 1;
            }
            jumps++;
            i -= i + 2 >= c.size() ? 1 : 0;
        }
        return jumps;
    }
    

    JavaScript Simpler Solution

    function jumpingOnClouds(c) {
        var jumps = 0
        jumps += 2 == c.length ? 1 : 0
        for(var i = 2; i < c.length; i+=2){
            if(c[i] == 1){
                i -= 1
            }
            jumps++
            i -= i + 2 >= c.length ? 1 : 0
        }
        return jumps
    }