16ms C++ unordered_map and vector


  • 0
    B

    class Solution {
    public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
    unordered_map<int,int> mapNum;
    vector<int> temp;
    int leng1 = nums1.size();
    int leng2 = nums2.size();
    for(int j=0;j<leng1;j++)
    mapNum[nums1.at(j)]++;
    for(int i = 0;i<leng2;i++)
    {
    if(mapNum[nums2.at(i)]!=0)
    {
    temp.push_back(nums2.at(i));
    mapNum[nums2.at(i)]=0;
    }
    }
    return temp;

    }
    

    };


Log in to reply
 

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