From 1256daac2497ed11bf4e200e495b031ba2d1a03a Mon Sep 17 00:00:00 2001 From: fw_qaq <82551626+Jack-Zhang-1314@users.noreply.github.com> Date: Tue, 18 Oct 2022 00:51:19 +0800 Subject: [PATCH] =?UTF-8?q?update=200349.=E4=B8=A4=E4=B8=AA=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E7=9A=84=E4=BA=A4=E9=9B=86.md=20about=20rust?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0349.两个数组的交集.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 153077ed..a6e07424 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -310,6 +310,22 @@ impl Solution { } ``` +解法2: + +```rust +use std::collections::HashSet; +impl Solution { + pub fn intersection(nums1: Vec, nums2: Vec) -> Vec { + nums1 + .into_iter() + .collect::>() + .intersection(&nums2.into_iter().collect::>()) + .copied() + .collect() + } +} +``` + C: ```C int* intersection1(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize){