1-line Python code


  • 0
    B
    class Solution(object):
    def intersection(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """
        return [x for x in set(nums1) if x in set(nums2)]

  • 0
    X

    Why My solution return set(nums1) & set(nums2)
    has something wrong?
    Exception: Type <type 'set'>: Not implemented


  • 0
    W

    Q`s request is :rtype: List[int] , solution is return list(set(nums1) & set(nums2))


  • 0
    D

    Just want to point out that we only need one of set(nums1) and set(nums2)


Log in to reply
 

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