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())

 

posted @ 2019-03-11 22:16  周洋  阅读(97)  评论(0编辑  收藏  举报