858. Mirror Reflection
Medium
Input: p = 2, q = 1
Output: 2
Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.Input: p = 3, q = 1
Output: 1Last updated
Input: p = 2, q = 1
Output: 2
Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.Input: p = 3, q = 1
Output: 1Last updated
class Solution:
def mirrorReflection(self, p: int, q: int) -> int:
m, n = 1,1
while m*p != n*q:
n += 1
m = n*q // p
if n % 2 == 1 and m % 2 == 0:
return 0
if n % 2 == 1 and m % 2 == 1:
return 1
if n % 2 == 0 and m % 2 == 1:
return 2
return -1