diff --git a/problems/0349.两个数组的交集.md b/problems/0349.两个数组的交集.md index 5e47ced8..905bf4b2 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 + ```