-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon_elements.cpp
More file actions
39 lines (39 loc) · 1.02 KB
/
Common_elements.cpp
File metadata and controls
39 lines (39 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Solution
{
public:
vector <int> commonElements (int A[], int B[], int C[], int n1, int n2, int n3)
{
//code here.
map<int,int> freq;
vector<int> res;
for(int i=0; i<n1;i++){
if(i>0 && A[i]!=A[i-1])
freq[A[i]]++;
else if(i==0){
freq[A[i]]++;
}
}
for(int i=0;i<n2;i++){
if(i>0 && B[i]!=B[i-1]){
freq[B[i]]++;
}
else if(i==0){
freq[B[i]]++;
}
}
for(int i=0;i<n3;i++){
if(i>0 && C[i]!=C[i-1]){
freq[C[i]]++;
}
else if(i==0){
freq[C[i]]++;
}
}
for(auto &x:freq){
if(x.second>=3){
res.push_back(x.first);
}
}
return res;
}
};