349. Intersection of Two Arrays
[Easy] “Given two arrays, write a function to compute their intersection."
Note: old solution, but trivial in Python, not really worth reviewing as it’s pretty downvoted.
Python3:
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
nums1dict = dict(zip(nums1, nums1))
nums2dict = dict(zip(nums2, nums2))
res = []
for n1 in nums1dict:
if n1 in nums2dict:
res.append(n1)
return(res)