My javascript solution


  • 0
    /**
     * @param {number[]} nums1
     * @param {number[]} nums2
     * @return {number[]}
     */
    var intersection = function(nums1, nums2) {
        nums1=onlySet(nums1);
        nums2=onlySet(nums2);
        var resultArr=[];
        for(var x in nums1){
            for(var y in nums2){
                if(nums1[x]==nums2[y]){
                    resultArr.push(nums2[y]);
                }
            }
        }
        return resultArr;
    };
    
    function onlySet(arr){
        var t=[];
        for(var i in arr){
            if(t.indexOf(arr[i])<0){
                t.push(arr[i]);
            }
        }
        return t;
    }
    

Log in to reply
 

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