You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution
public static String kangaroo(int x1, int v1, int x2, int v2) { if ((x2 > x1 && v2 >= v1) || (x1 > x2 && v1 >= v2)) { return "NO"; } else { int diff = Integer.MAX_VALUE, p1 = x1 + v1, p2 = x2 + v2; while (true) { if (p1 == p2) { return "YES"; } if (Math.abs(p1 - p2) > diff) { return "NO"; } diff = Math.abs(p1 - p2); p1 += v1; p2 += v2; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Number Line Jumps
You are viewing a single comment's thread. Return to all comments →
My Java 8 Solution