Update 0349.两个数组的交集.md

加入python使用数组方法
This commit is contained in:
ZerenZhang2022
2023-03-06 01:35:47 -05:00
committed by GitHub
parent 5ec197d1b4
commit 84326d9d61

View File

@ -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
```