Intuitive Javascript Solution


  • 0
    D
    var intersection = function(nums1, nums2) {
        let intersection = {};
        
        // collect unique intersections
        for (const n of nums1)
            if (nums2.indexOf(n) !== -1) intersection[n] = 1;
        
        // extract intersections and convert to numbers
        return Object.keys(intersection).map(val => parseInt(val));
    };
    

Log in to reply
 

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