feat: 3516_find_closest_person
This commit is contained in:
parent
a8b5c56bbf
commit
d5e093754a
7
3516_find_closest_person/Cargo.lock
generated
Normal file
7
3516_find_closest_person/Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "find_closest_person"
|
||||
version = "0.1.0"
|
6
3516_find_closest_person/Cargo.toml
Normal file
6
3516_find_closest_person/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "find_closest_person"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
13
3516_find_closest_person/src/lib.rs
Normal file
13
3516_find_closest_person/src/lib.rs
Normal file
@ -0,0 +1,13 @@
|
||||
pub struct Solution;
|
||||
|
||||
impl Solution {
|
||||
pub fn find_closest(x: i32, y: i32, z: i32) -> i32 {
|
||||
let distance_x = (x - z).abs();
|
||||
let distance_y = (y - z).abs();
|
||||
if distance_x == distance_y {
|
||||
0
|
||||
} else {
|
||||
if distance_x < distance_y { 1 } else { 2 }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user