当前位置:网站首页>K high frequency elements before sorting
K high frequency elements before sorting
2022-06-30 14:40:00 【Douglas_ LT】
A daily topic ing, Today is a day medium topic 347. Top K Frequent Elements
class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
unordered_map<int,int> umap;
for(int i=0;i<nums.size();i++){
umap[nums[i]]++;
}
priority_queue <pair<int,int>> pq;
for(auto p:umap){
pq.push(pair<int,int>(-p.second,p.first));
if(pq.size()>k){
pq.pop();
}
}
vector<int> ret;
for(int i=0;i<k;i++){
ret.push_back(pq.top().second);
pq.pop();
}
return ret;
}
};
边栏推荐
- Non decreasing column
- [extensive reading of papers] analyzing connections between user attributes, images, and text
- Summary of use of laravel DCAT admin
- Laravel configures passport and returns token using JWT
- Lihongyi machine learning 2020 homework summary
- 2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
- Summary of FTP network protocol learning
- @component使用案例
- jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections
- Problem: wechat developer tool visitor mode cannot use this function
猜你喜欢

Lihongyi machine learning 2020 homework summary

2021-05-12

Thinkphp5 log file contains trick

go channel && select

【BUUCTF】 EasySql

Shangpinhui knowledge points of large e-commerce projects

How does hbuilder display in columns?
![[extensive reading of papers] multimodal attribute extraction](/img/ec/546c107ac0d31deded7ca94fdf0e2d.jpg)
[extensive reading of papers] multimodal attribute extraction

Race of golang

XSS challenge (6-10) more detailed answers
随机推荐
Introduction to the construction and development of composer private warehouse
Wechat applet realizes map navigation + door-to-door recycling
Meaning of while (~scanf ("%d%d", & A, & B))
MySQL back to table query optimization
Zend studio how to import an existing project
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
Computer screenshot how to cut the mouse in
[extensive reading of papers] multi modal sarcasm detection and human classification in code mixed conversations
Attack and defense world web questions
For loop and promise to solve the problem of concurrent callback
Details of gets, fgetc, fgets, Getc, getchar, putc, fputc, putchar, puts, fputs functions
KnightCTF WEB
The first dark spring cup dnuictf
How does hbuilder display in columns?
ctfshow nodejs
Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit
Is it troublesome for CITIC futures to open an account? Is it safe? How much is the handling charge for opening an account for futures? Can you offer a discount
On simple code crawling Youdao translation_ 0's problem (to be solved)
Use PHP to delete the specified text content in the file
Thinkphp5 log file contains trick