Skip to content

Commit bde87d2

Browse files
authored
Added solution for 2956
1 parent 2931dbf commit bde87d2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::collections::HashSet;
2+
3+
impl Solution {
4+
// Create HashSet for nums1 and nums2. Then loop through nums1 and nums2 to check how many of them are available in the HashSets.
5+
pub fn find_intersection_values(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
6+
let mut set1 = HashSet::new();
7+
let mut set2 = HashSet::new();
8+
let mut result = vec![0, 0];
9+
10+
for num in &nums1 {
11+
let count = set1.insert((*num).to_string());
12+
}
13+
14+
for num in &nums2 {
15+
let count = set2.insert((*num).to_string());
16+
}
17+
18+
for num in &nums1 {
19+
if set2.contains(&((*num).to_string())) {
20+
result[0] += 1;
21+
}
22+
}
23+
24+
for num in &nums2 {
25+
if set1.contains(&((*num).to_string())) {
26+
result[1] += 1;
27+
}
28+
}
29+
30+
return result;
31+
}
32+
}

0 commit comments

Comments
 (0)