Check If N and Its Double Exist LeetCode solution in Rust

1
use std::collections::HashSet;
2

3
impl Solution {
4
pub fn check_if_exist(arr: Vec<i32>) -> bool {
5
let mut prev = HashSet::new();
6
for n in arr {
7
let double = n * 2;
8
if prev.contains(&double) {
9
return true;
10
}
11
if n & 1 == 0 {
12
let half = n / 2;
13
if prev.contains(&half) {
14
return true;
15
}
16
}
17
prev.insert(n);
18
}
19
false
20
}
21
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0