LeetCode Solutions
858. Mirror Reflection
Time: $O(\log p)$ Space: $O(1)$
class Solution {
public:
int mirrorReflection(int p, int q) {
while (p % 2 == 0 && q % 2 == 0) {
p /= 2;
q /= 2;
}
if (p % 2 == 0)
return 2;
if (q % 2 == 0)
return 0;
return 1;
}
};
class Solution {
public int mirrorReflection(int p, int q) {
while (p % 2 == 0 && q % 2 == 0) {
p /= 2;
q /= 2;
}
if (p % 2 == 0)
return 2;
if (q % 2 == 0)
return 0;
return 1;
}
}
class Solution:
def mirrorReflection(self, p: int, q: int) -> int:
while p % 2 == 0 and q % 2 == 0:
p //= 2
q //= 2
if p % 2 == 0:
return 2
if q % 2 == 0:
return 0
return 1