1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
var intersection = function(nums1, nums2) { if (nums1.length > nums2.length) { return intersection(nums2, nums1); } const result = []; const map = new Map(); for (const v of nums2) { map.set(v, 0); }
for (const v of nums1) { map.has(v) && (map.set(v, 1)); }
for (const [key, value] of map.entries()) { value && (result.push(key)); }
return result; };
|