We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 08b0bf4 commit 7b200deCopy full SHA for 7b200de
scripts/algorithms/C/Check If N and Its Double Exist/Check If N and Its Double Exist.rs
@@ -0,0 +1,23 @@
1
+// Runtime: 0 ms (Top 100.0%) | Memory: 2.20 MB (Top 56.82%)
2
+
3
+use std::collections::HashSet;
4
5
+impl Solution {
6
+ pub fn check_if_exist(arr: Vec<i32>) -> bool {
7
+ let mut prev = HashSet::new();
8
+ for n in arr {
9
+ let double = n * 2;
10
+ if prev.contains(&double) {
11
+ return true;
12
+ }
13
+ if n & 1 == 0 {
14
+ let half = n / 2;
15
+ if prev.contains(&half) {
16
17
18
19
+ prev.insert(n);
20
21
+ false
22
23
+}
0 commit comments