diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 0cbdf85f..28867092 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -238,6 +238,25 @@ class Solution { } ``` +Rust: +```rust +use std::collections::HashSet; +impl Solution { + pub fn intersection(nums1: Vec, nums2: Vec) -> Vec { + let mut resultSet: HashSet = HashSet::with_capacity(1000); + let nums1Set: HashSet = nums1.into_iter().collect(); + + for num in nums2.iter() { + if nums1Set.contains(num) { + resultSet.insert(*num); + } + } + + let ret: Vec = resultSet.into_iter().collect(); + ret + } +} +``` ## 相关题目 * 350.两个数组的交集 II