mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
rs: add «2540. Minimum Common Value»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
fe9f5ac9da
commit
46088cf458
1 changed files with 11 additions and 0 deletions
11
rs/minimum-common-value.rs
Normal file
11
rs/minimum-common-value.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
impl Solution {
|
||||||
|
pub fn get_common(xs: Vec<i32>, ys: Vec<i32>) -> i32 {
|
||||||
|
if xs.len() > ys.len() {
|
||||||
|
return Self::get_common(ys, xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
xs.into_iter()
|
||||||
|
.find(|x| ys.binary_search(&x).is_ok())
|
||||||
|
.unwrap_or(-1)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue