Skip to content

Commit 6bb1dec

Browse files
authored
Add files via upload (#253)
1 parent 304143a commit 6bb1dec

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Leetocode 1338 solution.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int minSetSize(vector<int>& arr) {
4+
vector<pair<int,int>> ans;
5+
unordered_map<int,int> m;
6+
for(auto x:arr)
7+
m[x]++;
8+
for(auto x:m)
9+
ans.push_back({x.second,x.first});
10+
sort(ans.begin(),ans.end(),greater<pair<int,int>>());
11+
int fans=0,temp=0,n=arr.size()/2;
12+
for(int i=0;i<ans.size();i++)
13+
{
14+
temp+=ans[i].first;
15+
fans++;
16+
if(temp>=n)
17+
return fans;
18+
}
19+
return 0;
20+
}
21+
};

0 commit comments

Comments
 (0)