my javascript solution


  • 0
    Z
    /**
     * @param {number[]} nums1
     * @param {number[]} nums2
     * @return {number[]}
     */
    function intersection(nums1, nums2) {
        const set = new Set([...nums1]), res = new Set();
        for (let i = 0; i < nums2.length; i++) {
            if (set.has(nums2[i])) {
                res.add(nums2[i]);
            }
        }
        return [...res];
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.