12ms C++ using map and vector


  • 0
    L

    class Solution {
    public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
    map<int ,int > couns1;
    map<int ,int > couns2;
    for(int i=0;i<nums1.size();i++)
    {
    couns1.insert({nums1[i],i});
    }
    vector<int> resu;
    for(int i=0;i<nums2.size();i++)
    {
    if(couns1.find(nums2[i])==couns1.end()) continue;
    else
    {
    if(resu.end()==find(resu.begin(),resu.end(),nums2[i]))
    resu.push_back(nums2[i]);
    else continue;
    }
    }
    return resu;
    }
    };


Log in to reply
 

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