Skip to content

Commit 84326d9

Browse files
Update 0349.两个数组的交集.md
加入python使用数组方法
1 parent 5ec197d commit 84326d9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

problems/0349.两个数组的交集.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ class Solution:
169169
val_dict[num] = 0
170170

171171
return ans
172+
173+
class Solution: # 使用数组方法
174+
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
175+
count1 = [0]*1001
176+
count2 = [0]*1001
177+
result = []
178+
for i in range(len(nums1)):
179+
count1[nums1[i]]+=1
180+
for j in range(len(nums2)):
181+
count2[nums2[j]]+=1
182+
for k in range(1001):
183+
if count1[k]*count2[k]>0:
184+
result.append(k)
185+
return result
186+
172187
```
173188

174189

0 commit comments

Comments
 (0)