码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode 350. Intersection of Two Arrays II

时间:2019-03-11 22:28:23      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:return   imp   bsp   counter   array   elements   list   leetcode   etc   

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

 

Leetcode 350. Intersection of Two Arrays II

标签:return   imp   bsp   counter   array   elements   list   leetcode   etc   

原文地址:https://www.cnblogs.com/zywscq/p/10513623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!