LeetCode 349. Intersection of Two Arrays JavaScript Solution

preview_player
Показать описание
A brief walkthrough of LeetCode problem 349, Intersection of Two Arrays, in JavaScript.

Solution adapted from suxiaohui1996 at
Рекомендации по теме
Комментарии
Автор

You can do this in 2 lines of code:

const set = new Set(nums1);
return nums2.filter(value => set.has(value));

Or 3 lines if you want to de-dupe by wrapping the filtered array in another set.

IceMetalPunk