Python Solution - LMK what you think


  • 0
    K

    from collections import Counter

    def intersect(self, nums1, nums2):
    
        dict1 = Counter(nums1)
        dict2 = Counter(nums2)
    
        similar = []
    
        for key,value in dict1.iteritems():
            if key in dict2:
                similar.extend([key]*min(value,dict2[key]))
    
    
        return similar

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.