-
Notifications
You must be signed in to change notification settings - Fork 2
/
two-out-of-three.rs
37 lines (29 loc) · 943 Bytes
/
two-out-of-three.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![allow(dead_code, unused, unused_variables, non_snake_case)]
use std::collections::HashSet;
fn main() {}
struct Solution;
impl Solution {
pub fn two_out_of_three(nums1: Vec<i32>, nums2: Vec<i32>, nums3: Vec<i32>) -> Vec<i32> {
use std::collections::HashSet;
let mut hash1: HashSet<_> = nums1.iter().collect();
let mut hash2 = HashSet::new();
let mut hash3 = HashSet::new();
let mut result = vec![];
for i in nums2.iter() {
if hash1.contains(i) && !hash2.contains(i) {
result.push(*i);
}
hash2.insert(*i);
}
for i in nums3.iter() {
if ((hash1.contains(i) && !hash2.contains(i))
|| (!hash1.contains(i) && hash2.contains(i)))
&& !hash3.contains(i)
{
result.push(*i);
}
hash3.insert(*i);
}
result
}
}