#include using namespace std; class Solution { public: vector topKFrequent(vector &nums, int k) { unordered_map nums_count; for (auto x : nums) { nums_count[x]++; } multimap> big_m; for (auto x : nums_count) { big_m.insert(make_pair(x.second, x.first)); } vector res; for (auto it = big_m.begin(); it != big_m.end() && k; it++, k--) { res.push_back(it->second); } return res; } };