Nlogn time and n space but super easy to understand


#1

vector Solution::solve(vector &A, vector &B, vector &C) {
sort(A.begin(), A.end());
sort(B.begin(), B.end());
sort(C.begin(), C.end());
vector a,b,c,v;
a.push_back(A[0]);
for(int i=1;i<A.size();i++){
if(A[i]!=A[i-1]){
a.push_back(A[i]);
}
}
b.push_back(B[0]);
for(int i=1;i<B.size();i++){
if(B[i]!=B[i-1]){
b.push_back(B[i]);
}
}
c.push_back(C[0]);
for(int i=1;i<C.size();i++){
if(C[i]!=C[i-1]){
c.push_back(C[i]);
}
}
map<int,int> m;
for(auto x:a){
m[x]++;
}
for(auto x:b){
m[x]++;
}
for(auto x:c){
m[x]++;
}
set s;
for(int i=0;i<a.size();i++){
if(m[a[i]]>=2){
s.insert(a[i]);
}
}
for(int i=0;i<b.size();i++){
if(m[b[i]]>=2){
s.insert(b[i]);
}
}
for(int i=0;i<c.size();i++){
if(m[c[i]]>=2){
s.insert(c[i]);
}
}
for(auto it=s.begin();it!=s.end();it++){
v.push_back(*(it));
}
return v;

}