Merge pull request #1929 from ZerenZhang2022/patch-12

Update 0349.两个数组的交集.md
This commit is contained in:
程序员Carl
2023-03-11 09:35:28 +08:00
committed by GitHub

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