858. Mirror Reflection Medium
1/**
2 * [858] Mirror Reflection
3 *
4 * There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2.
5 * The square room has walls of length p and a laser ray from the southwest corner first meets the east wall at a distance q from the 0^th receptor.
6 * Given the two integers p and q, return the number of the receptor that the ray meets first.
7 * The test cases are guaranteed so that the ray will meet a receptor eventually.
8 *
9 * Example 1:
10 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/06/18/reflection.png" style="width: 218px; height: 217px;" />
11 * Input: p = 2, q = 1
12 * Output: 2
13 * Explanation: The ray meets receptor 2 the first time it gets reflected back to the left wall.
14 *
15 * Example 2:
16 *
17 * Input: p = 3, q = 1
18 * Output: 1
19 *
20 *
21 * Constraints:
22 *
23 * 1 <= q <= p <= 1000
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/mirror-reflection/
29// discuss: https://leetcode.com/problems/mirror-reflection/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn mirror_reflection(p: i32, q: i32) -> i32 {
35 0
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_858() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.