3516. Find Closest Person Easy

@problem@discussion
#Math



1/**
2 * [3516] Find Closest Person
3 *
4 * <p data-end="116" data-start="0">You are given three integers <code data-end="33" data-start="30">x, <code data-end="38" data-start="35">y, and <code data-end="47" data-start="44">z, representing the positions of three people on a number line:
5 * <ul data-end="252" data-start="118">
6 * 	<li data-end="154" data-start="118"><code data-end="123" data-start="120">x is the position of Person 1.
7 * 	<li data-end="191" data-start="155"><code data-end="160" data-start="157">y is the position of Person 2.
8 * 	<li data-end="252" data-start="192"><code data-end="197" data-start="194">z is the position of Person 3, who does not move.
9 * 
10 * <p data-end="322" data-start="254">Both Person 1 and Person 2 move toward Person 3 at the same speed.
11 * <p data-end="372" data-start="324">Determine which person reaches Person 3 first:
12 * <ul data-end="505" data-start="374">
13 * 	<li data-end="415" data-start="374">Return 1 if Person 1 arrives first.
14 * 	<li data-end="457" data-start="416">Return 2 if Person 2 arrives first.
15 * 	<li data-end="505" data-start="458">Return 0 if both arrive at the same time.
16 * 
17 * <p data-end="537" data-is-last-node="" data-is-only-node="" data-start="507">Return the result accordingly.
18 *  
19 * <strong class="example">Example 1:
20 * <div class="example-block">
21 * Input: <span class="example-io">x = 2, y = 7, z = 4</span>
22 * Output: <span class="example-io">1</span>
23 * Explanation:
24 * <ul data-end="258" data-start="113">
25 * 	<li data-end="193" data-start="113">Person 1 is at position 2 and can reach Person 3 (at position 4) in 2 steps.
26 * 	<li data-end="258" data-start="194">Person 2 is at position 7 and can reach Person 3 in 3 steps.
27 * 
28 * <p data-end="317" data-is-last-node="" data-is-only-node="" data-start="260">Since Person 1 reaches Person 3 first, the output is 1.
29 * </div>
30 * <strong class="example">Example 2:
31 * <div class="example-block">
32 * Input: <span class="example-io">x = 2, y = 5, z = 6</span>
33 * Output: <span class="example-io">2</span>
34 * Explanation:
35 * <ul data-end="245" data-start="92">
36 * 	<li data-end="174" data-start="92">Person 1 is at position 2 and can reach Person 3 (at position 6) in 4 steps.
37 * 	<li data-end="245" data-start="175">Person 2 is at position 5 and can reach Person 3 in 1 step.
38 * 
39 * <p data-end="304" data-is-last-node="" data-is-only-node="" data-start="247">Since Person 2 reaches Person 3 first, the output is 2.
40 * </div>
41 * <strong class="example">Example 3:
42 * <div class="example-block">
43 * Input: <span class="example-io">x = 1, y = 5, z = 3</span>
44 * Output: <span class="example-io">0</span>
45 * Explanation:
46 * <ul data-end="245" data-start="92">
47 * 	<li data-end="174" data-start="92">Person 1 is at position 1 and can reach Person 3 (at position 3) in 2 steps.
48 * 	<li data-end="245" data-start="175">Person 2 is at position 5 and can reach Person 3 in 2 steps.
49 * 
50 * <p data-end="304" data-is-last-node="" data-is-only-node="" data-start="247">Since both Person 1 and Person 2 reach Person 3 at the same time, the output is 0.
51 * </div>
52 *  
53 * Constraints:
54 * 
55 * 	1 <= x, y, z <= 100
56 * 
57 */
58pub struct Solution {}
59
60// problem: https://leetcode.com/problems/find-closest-person/
61// discuss: https://leetcode.com/problems/find-closest-person/discuss/?currentPage=1&orderBy=most_votes&query=
62
63// submission codes start here
64
65impl Solution {
66    pub fn find_closest(x: i32, y: i32, z: i32) -> i32 {
67        0
68    }
69}
70
71// submission codes end
72
73#[cfg(test)]
74mod tests {
75    use super::*;
76
77    #[test]
78    fn test_3516() {
79    }
80}
81

Back
© 2026 bowen.ge All Rights Reserved.