rustgym/leetcode/
_349_intersection_of_two_arrays.rs1struct Solution;
2
3use std::collections::HashSet;
4
5impl Solution {
6    fn intersection(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
7        let h1: HashSet<i32> = nums1.into_iter().collect();
8        let h2: HashSet<i32> = nums2.into_iter().collect();
9        let bitand = &h1 & &h2;
10        bitand.into_iter().collect()
11    }
12}
13
14#[test]
15fn test() {
16    let nums1 = vec![1, 2, 2, 1];
17    let nums2 = vec![2, 2];
18    assert_eq!(Solution::intersection(nums1, nums2), vec![2]);
19}