You are viewing a single comment's thread. Return to all comments →
public static int jumpingOnClouds(List<Integer> c) { // Write your code here
int jumps = 0; int i = 0;
while (i < c.size() - 1) { // Prefer jumping 2 steps if possible, otherwise jump 1 step if (i + 2 < c.size() && c.get(i + 2) == 0) { i += 2; } else { i += 1; } jumps++; // Count the jump } return jumps; }
Seems like cookies are disabled on this browser, please enable them to open this website
Jumping on the Clouds
You are viewing a single comment's thread. Return to all comments →
int jumps = 0; int i = 0;