Js functional solution


  • 0
    C
    var intersection = function(nums1, nums2) {
        var hash = {};
        nums1.forEach(num => {
            if (!hash[num]) hash[num] = true;
        });
        return nums2.filter(num => {
            if (!hash[num]) return false;
            hash[num] = false;
            return true;
        });
    };
    

Log in to reply
 

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