We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8daa7f1 + 2bf5950 commit 5452a5aCopy full SHA for 5452a5a
rust/2215-find-the-difference-of-two-arrays.rs
@@ -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