力扣350. 两个数组的交集 II
2021-03-03 13:27
标签:bsp cti 交集 lis rgb tps -o arrays leetcode 原题 力扣350. 两个数组的交集 II 标签:bsp cti 交集 lis rgb tps -o arrays leetcode 原文地址:https://www.cnblogs.com/lj95/p/14392365.html 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