Kangaroo jump problem Solution (Hacker Rank)
Problem
Solution
static string kangaroo(int x1, int v1, int x2, int v2)
{
int
kangarro1 = x1 + v1;
int
kangarro2 = x2 + v2;
while (kangarro1 <= 10000 || kangarro2 >= 10000)
{
if (kangarro1 == kangarro2)
{
return "YES";
}
kangarro1 = kangarro1 + v1;
kangarro2 = kangarro2 + v2;
}
return "NO";
}
No comments:
Post a Comment