Check If N and Its Double Exist LeetCode solution in Rust
1use std::collections::HashSet;23impl Solution {4pub fn check_if_exist(arr: Vec<i32>) -> bool {5let mut prev = HashSet::new();6for n in arr {7let double = n * 2;8if prev.contains(&double) {9return true;10}11if n & 1 == 0 {12let half = n / 2;13if prev.contains(&half) {14return true;15}16}17prev.insert(n);18}19false20}21}