My python solution using set function


  • 0
    Y

    It's simple to use the set function and return the overlap of the two list.

        def intersection(self, nums1, nums2):
            """
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: List[int]
            """
            if nums1==[] or nums2==[]:return []
            set1=set(nums1)
            set2=set(nums2)
            return list(set1&set2)
    

Log in to reply
 

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