""" 0349.1 - Intersection of Two Arrays - Solution 1 - Set Intersection """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
"""Intersection of Two Arrays Function"""
return list(set(nums1) & set(nums2))
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().intersection([1, 2, 2, 1], [2, 2])) # [2]
print(Solution().intersection([4, 9, 5], [9, 4, 9, 8, 4])) # [9, 4]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0349.2 - Intersection of Two Arrays - Solution 2 - Hash Set with Manual Lookup """
#####################################################################################
# Imports
#####################################################################################
from typing import List
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
"""Intersection of Two Arrays Function"""
set1 = set(nums1)
result = set()
for num in nums2:
if num in set1:
result.add(num)
return list(result)
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().intersection([1, 2, 2, 1], [2, 2])) # [2]
print(Solution().intersection([4, 9, 5], [9, 4, 9, 8, 4])) # [9, 4]
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()