Skip to content

Commit 5452a5a

Browse files
authored
Merge pull request #5026 from CarlosGuzman01/main
Create 2215-find-the-difference-of-two-arrays.rs
2 parents 8daa7f1 + 2bf5950 commit 5452a5a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::collections::HashSet;
2+
3+
impl Solution {
4+
pub fn find_difference(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<Vec<i32>> {
5+
6+
let s1: HashSet<i32> = nums1.into_iter().collect();
7+
let s2: HashSet<i32> = nums2.into_iter().collect();
8+
9+
let mut r1: HashSet<i32> = HashSet::new();
10+
let mut r2: HashSet<i32> = HashSet::new();
11+
12+
for n in &s1{
13+
if !s2.contains(n){
14+
r1.insert(*n);
15+
}
16+
}
17+
18+
for n in &s2{
19+
if !s1.contains(n){
20+
r2.insert(*n);
21+
}
22+
}
23+
24+
vec![
25+
r1.into_iter().collect(),
26+
r2.into_iter().collect(),
27+
]
28+
29+
}
30+
}

0 commit comments

Comments
 (0)