VISUALGO//PROBLEMS
find the difference of two arrays · hash map / seteasy
nums1 → set1
nums2 → set2
only in set1
·
only in set2
·
ELEMENTS
nums1
nums2
Python
def findDifference(nums1: list[int], nums2: list[int]) -> list[list[int]]:
set1 = set(nums1)
set2 = set(nums2)
only_in_1 = [x for x in set1 if x not in set2]
only_in_2 = [x for x in set2 if x not in set1]
return [only_in_1, only_in_2]