标签:amp queue second return turn top pre 元素 cto
1 class Solution 2 { 3 public: 4 vector<int> topKFrequent(vector<int>& nums, int k) 5 { 6 vector<int> res; 7 unordered_map<int,int> hash; 8 for(auto a : nums) hash[a] ++; 9 priority_queue<pair<int,int>> pq; 10 for(auto a : hash) pq.push({a.second,a.first}); 11 while(k --) 12 { 13 if(!pq.empty()) 14 { 15 res.push_back(pq.top().second); 16 pq.pop(); 17 } 18 } 19 return res; 20 } 21 };
标签:amp queue second return turn top pre 元素 cto
原文地址:https://www.cnblogs.com/yuhong1103/p/12755313.html