Skip to content

Commit f6b887e

Browse files
authored
Find Majority Elements
1 parent 864a634 commit f6b887e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

findMajorityElements.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
map < long long , long long > mp;
4+
vector <long long > vi;
5+
set<long long >st;
6+
int main()
7+
{
8+
9+
long long int tc , temp_tc;
10+
cin>>tc;
11+
temp_tc = tc/3;
12+
while(tc--)
13+
{
14+
long long int n;
15+
cin>>n;
16+
mp[n]++;
17+
if(mp[n]>temp_tc) st.insert(n);
18+
}
19+
for(int i:st)
20+
{
21+
cout<<i<<" ";
22+
}
23+
cout<<endl;
24+
}

0 commit comments

Comments
 (0)