From c7f68825e7a27499f4959f8c6d25d444a36b8227 Mon Sep 17 00:00:00 2001 From: YiChih Wang Date: Sun, 12 Sep 2021 13:49:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A00349.=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E7=9A=84=E4=BA=A4=E9=9B=86Rust=E8=AA=9E?= =?UTF-8?q?=E8=A8=80=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Note: - leetcode提交通過 --- problems/0349.两个数组的交集.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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