Python solution 40~50 ms


  • 0
    N
    class Solution(object):
        def intersection(self, nums1, nums2):
            """
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: List[int]
            """
            res = set()
            nums2_set = set(nums2)
            for i in (nums1):
                if i in nums2_set:
                    res.add(i)
            
            return list(res)
    

Log in to reply
 

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