One Line Python Solutions

  • -1
    return {thing: 1 for thing in nums1 if thing in nums2}.keys()

    Use a dictionary comprehension with a conditional to get all keys in both lists. The dictionary will make sure that the keys are unique; then, just return the keys from the dictionary.

    Or, using sets.

    return list(set(nums1).intersection(nums2))

Log in to reply

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