C++,map


  • 0
    B

    class Solution {
    public:
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
    int leng1 = nums1.size();
    int leng2 = nums2.size();
    map<int,int> mapTemp;
    vector<int> interS;
    for(int i =0;i<leng1;i++)
    {
    mapTemp[nums1.at(i)]++;
    }
    for(int j =0 ;j<leng2;j++)
    {
    if(mapTemp[nums2.at(j)])
    {
    interS.push_back(nums2.at(j));
    --mapTemp[nums2.at(j)];
    }
    }
    return interS;
    }
    };


Log in to reply
 

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