Leetcode 350. Intersection of Two Arrays II

python可重集合的操作

class Solution(object):
    def intersect(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        from collections import Counter
        c1 = Counter(nums1)
        c2 = Counter(nums2)
        return list((c1&c2).elements())
原文地址:https://www.cnblogs.com/zywscq/p/10513623.html