标签:solution count src obj 交集 return def ret class
class Solution(object):
def intersect(self, nums1, nums2):
if len(nums1) > len(nums2):
return self.intersect(nums2, nums1)
m = collections.Counter()
for num in nums1:
m[num] += 1
intersection = list()
for num in nums2:
if m.get(num) > 0:
intersection.append(num)
m[num] -= 1
if m[num] == 0:
m.pop(num)
return intersection
标签:solution count src obj 交集 return def ret class
原文地址:https://www.cnblogs.com/Ann21/p/14605065.html