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

 

相关文章:

  • 2021-06-28
  • 2022-12-23
  • 2021-10-14
  • 2021-09-01
  • 2022-12-23
  • 2021-07-07
  • 2021-05-26
猜你喜欢
  • 2021-10-04
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
相关资源
相似解决方案