class Solution {
public:
static bool cmp(pair<int,int> a,pair<int,int> b){
return a.second > b.second;
}
vector<int> topKFrequent(vector<int>& nums, int k) {
map<int,int> m;
for(int i=0; i<nums.size();i++){
m[nums[i]]++;
}
vector<pair<int,int>>vt(m.begin(),m.end());
sort(vt.begin(),vt.end(),cmp);
vector<int> end(k);
vector<pair<int,int>>::iterator itea =vt.begin();
int ss =itea->first;
for(int i=0;i<k;i++){
end[i]=itea->first;
itea++;
}
return end;
}
};