Here is my solution. But I think the runtime is O(klog(n)). Because I popped the priority queue k times. Each pop of a priority queue take log(n). Is that right?

```
//https://leetcode.com/problems/top-k-frequent-elements/description/
class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
unordered_map<int, int> map; // value -> frequency
priority_queue< pair<int,int> > q; // /frequency -> value ; max priority queue
for(int x : nums) { // record the frequency in the map
map[x]++;
}
vector<int> output;
for(auto x : map){
q.push(make_pair(x.second, x.first)); // reverse key and value pair
}
while(q.size() && k){
output.push_back(q.top().second); // queue: frequency -> value
k--;
q.pop();
}
return output;
}
};
```