From 8d797eaa7731221cc7a3ca7aa1ddc134d9c8d0df Mon Sep 17 00:00:00 2001 From: jenliketen Date: Tue, 25 May 2021 20:14:01 -0400 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=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=86=20python3?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0349.两个数组的交集.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 46e15482..fe019a0a 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -118,6 +118,17 @@ class Solution { ``` Python: +```python3 +class Solution: + def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: + result_set = set() + + set1 = set(nums1) + for num in nums2: + if num in set1: + result_set.add(num) # set1里出现的nums2元素 存放到结果 + return result_set +``` Go: