From 84326d9d6154626f907cddedc59d37f35acb44a6 Mon Sep 17 00:00:00 2001 From: ZerenZhang2022 <118794589+ZerenZhang2022@users.noreply.github.com> Date: Mon, 6 Mar 2023 01:35:47 -0500 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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加入python使用数组方法 --- problems/0349.两个数组的交集.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 347d1094..b7365e6e 100644 --- a/problems/0349.两个数组的交集.md +++ b/problems/0349.两个数组的交集.md @@ -169,6 +169,21 @@ class Solution: val_dict[num] = 0 return ans + +class Solution: # 使用数组方法 + def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: + count1 = [0]*1001 + count2 = [0]*1001 + result = [] + for i in range(len(nums1)): + count1[nums1[i]]+=1 + for j in range(len(nums2)): + count2[nums2[j]]+=1 + for k in range(1001): + if count1[k]*count2[k]>0: + result.append(k) + return result + ```