349. Intersection of Two Arrays
202410122251
tags: #array
var intersection = function(nums1, nums2) {
const allSet = new Set(nums1.concat(nums2));
const set1 = new Set(nums1);
const set2 = new Set(nums2);
const res = [];
for (const num of allSet) {
if (set1.has(num) && set2.has(num)) {
res.push(num);
}
}
return res;
};