'''
keys: 
Solutions:
Similar: 
T:
S:
'''
from typing import List


class Solution:
    # O(n+m) for S and T
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        if not nums1 or not nums2: return []
        if len(nums1) < len(nums2): return self.intersection(nums2, nums1)
        
        s1 = set(nums1); s2 = set(nums2)
        res = []
        for val in s1:
            if val in s2:
                res.append(val)
        return res
    
    
    # built-in; O(n+m) for S and T
    def intersection1(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: List[int]
        """  
        set1 = set(nums1)
        set2 = set(nums2)
        return list(set2 & set1)