Skip to content

Instantly share code, notes, and snippets.

@vmamore
Last active October 6, 2020 02:29
Show Gist options
  • Select an option

  • Save vmamore/cc2b0588f9bb1c760cacfea9891efb5c to your computer and use it in GitHub Desktop.

Select an option

Save vmamore/cc2b0588f9bb1c760cacfea9891efb5c to your computer and use it in GitHub Desktop.
static int jumpingOnClouds(int[] c) {
int totalJumps = 0;
if (c.Length == 2)
{
if (c[0] == 0 && c[1] == 0)
return 1;
else
return 0;
}
for (int i = 0; i < c.Length;)
{
var nextCloud = i + 1;
var nextNextCloud = i + 2;
if (nextNextCloud < c.Length)
{
if (c[nextNextCloud] == 0)
{
totalJumps++;
i = nextNextCloud;
continue;
}
}
if (nextCloud < c.Length)
{
if (c[nextCloud] == 0)
{
totalJumps++;
i = nextCloud;
continue;
}
}
i++;
}
return totalJumps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment