Mirror Reflection LeetCode solution in JavaScript
1// Time complexity: O(log (min(p,q))2// Space complexity: O(1)34var mirrorReflection = function (p, q) {5let ext = q,6ref = p;78while (ext % 2 == 0 && ref % 2 == 0) {9ext /= 2;10ref /= 2;11}1213if (ext % 2 == 0 && ref % 2 == 1) return 0;14if (ext % 2 == 1 && ref % 2 == 1) return 1;15if (ext % 2 == 1 && ref % 2 == 0) return 2;1617return -1;18};