C++ | Two out of Three | unordered_map + set


#1
vector<int> Solution::solve(vector<int> &A, vector<int> &B, vector<int> &C) {
    unordered_map<int, int> umap;
    set<int> vec;
    vector<int> res;

    sort (A.begin(), A.end());
    sort (B.begin(), B.end());
    sort (C.begin(), C.end());

    for (auto it: A)
        if (*(lower_bound(B.begin(), B.end(), it)) == it or \
            *(lower_bound(C.begin(), C.end(), it)) == it)
            vec.insert(it);

    for (auto it: B)
        if (*(lower_bound(C.begin(), C.end(), it)) == it)
            vec.insert(it);

    for(auto it: vec)   res.push_back(it);
    return res;
}