Python hashtable solution


  • 1
    W
    class Solution(object):
        def intersect(self, nums1, nums2):
            d = {}
            for n in nums1:
                d[n] = d.get(n, 0) + 1
            
            ret = []
            for n in nums2:
                if d.get(n) > 0:
                    ret.append(n)
                    d[n] -= 1
                    
            return ret
    

Log in to reply
 

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