class Solution { public: vector topKFrequent(vector& nums, int k) { unordered_map freq; for(int n : nums){ freq[n]++; } vector ans; for(int i = 0 ; i < k ; i++){ int large = 0, key = 0; for( auto& f : freq ) { if( f.second > large ) { large = f.second; key = f.first; } } ans.push_back(key); freq[key] = 0; } return ans; } };