mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #1929 from ZerenZhang2022/patch-12
Update 0349.两个数组的交集.md
This commit is contained in:
@ -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
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user