Easy HashMap based solution in C++


#1
void fill(map<int,int>&m,vector<int>&v)
{
    for(auto it:v)
    {
        m[it]++;
    }
}
vector<int> Solution::solve(vector<int> &A, vector<int> &B, vector<int> &C)
{
    vector<int>ans;
    map<int,int>one,two,three,main;
    fill(one,A);
    fill(two,B);
    fill(three,C);
    fill(main,A);
    fill(main,B);
    fill(main,C);
    for(auto it:main)
    {
        bool o=one.find(it.first)!=one.end(),t=two.find(it.first)!=two.end();
        bool h=three.find(it.first)!=three.end();
        if((o && t) || (t && h) || (h && o))
        {
            ans.push_back(it.first);
        }
    }
    return ans;
}