Simplest to code + understand soultion in this editorial (C++)


#1
vector<int> Solution::solve(vector<int> &A, vector<int> &B, vector<int> &C) {
    unordered_map<int, int> map;
    vector<int> ans;
    
    sort(A.begin(), A.end());sort(B.begin(), B.end());sort(C.begin(), C.end());
    A.erase( unique( A.begin(), A.end() ), A.end() );
    B.erase( unique( B.begin(), B.end() ), B.end() );
    C.erase( unique( C.begin(), C.end() ), C.end() );
    
    
    for(int i = 0; i<A.size(); i++){
        map[A[i]] += 1;
    }
    
    for(int i = 0; i<B.size(); i++){
        map[B[i]] += 1;
    }
    
    for(int i = 0; i<C.size(); i++){
        map[C[i]] += 1;
    }
    
    for(auto j : map){
        if(j.second >= 2) ans.push_back(j.first);
    }
    sort(ans.begin(), ans.end());
    
    return ans;
}

#2

why have you used unordered map when you can use an ordered map to avoid sorting .