C++ hash-map solution


  • 0
    4
    vector< int > intersection( vector < int > & nums1, vector < int > & nums2 )
    {
        unordered_map < int, bool > umap;
        for( auto i : nums1 ) umap[i] = 1;
        vector < int > out;
        for( auto i : nums2 ) if( umap[i] ) { umap[i] = 0; out.push_back( i ); }
        return out;
    }

Log in to reply
 

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