1 class Solution:
2 def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
3 dic1,dic2 = {},{}
4 def helper(nums,dic):
5 for n in nums:
6 if n in dic:
7 dic[n] += 1
8 else:dic[n] = 1
9 helper(nums1,dic1)
10 helper(nums2,dic2)
11 ans = []
12 for i in dic1:
13 if i in dic2:
14 ans += (min(dic1[i],dic2[i])) * [i]
15 return ans
手机扫一扫
移动阅读更方便
你可能感兴趣的文章