프로그래밍
[Hackerrank] Jumping On Cloud
tedhong
2023. 2. 20. 12:52
2019-05-20 글쓴이 TED HONG
[Hackerrank] Jumping On Cloud
한 번에 최대 두칸 이동 가능
상태값이 1인 좌표로는 이동 불가
총 몇회 점프를 했는지 구하는 문제
static int jumpingOnClouds(int[] c)
{
int jumpCount = 0;
int num = 0;
int jumpPower = 2;
for (int i = 0; i < c.Length; i++)
{
jumpPower--;
if(jumpPower == 0 || (jumpPower == 1 && c[i] == 1))
{
jumpPower = 2;
jumpCount++;
}
}
return jumpCount;
}