Merge pull request #739 from andywang0607/349_rust

增加0349.两个数组的交集Rust語言版本
This commit is contained in:
程序员Carl 2021-09-14 10:13:52 +08:00 committed by GitHub
commit 88ace57df7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 0 deletions

View File

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