C++ simple 8 lines solution


  • 0
     vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
            vector<int>res;
            unordered_map<int,int>m;
            for(int i=0;i<nums2.size();i++) m[nums2[i]]++;
            for(int i=0;i<nums1.size();i++){
                if(m[nums1[i]]>0) res.push_back(nums1[i]);
                m[nums1[i]]=0;
            }
            return res;
        }
    

Log in to reply
 

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