当前位置:网站首页>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;
}
};
边栏推荐
- [extensive reading of papers] attributes guided facial image completion
- Summary of use of laravel DCAT admin
- DiceCTF - knock-knock
- C language & the difference between the address pointed to and the address pointed to by the pointer
- Lihongyi machine learning 2020 homework summary
- Detailed explanation of the first three passes of upload Labs
- [extensive reading of papers] analyzing connections between user attributes, images, and text
- Use of laravel repository mode
- The difference between settimeout() and setinterval()
- 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
猜你喜欢

Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
![[geek challenge 2019] PHP problem solving record](/img/bf/038082e8ee1c91eaf6e35add39f760.jpg)
[geek challenge 2019] PHP problem solving record

Using docker to manage MySQL services under Windows

XSS challenge (6-10) more detailed answers

Learn about data kinship JSON format design from sqlflow JSON format

【BUUCTF】 Have Fun

Introduction to the construction and development of composer private warehouse

Lihongyi machine learning 2020 homework summary

Zend studio how to import an existing project

Error on datetime when importing SQL file from MySQL
随机推荐
PHP recursive multi-level classification, infinite classification
ThinkPHP v3.2 comment annotation injection write shell
Att & CK red team evaluation field (I)
Summary of FTP network protocol learning
The difference between settimeout() and setinterval()
V3 02——What‘s new in Chrome extensions
2021-05-12
Double pointer palindrome string
XSS challenge (6-10) more detailed answers
notepad正则删除关键词所在行
Alipay certificate mode payment interface
ES6 notes
How to use Alibaba Vector Icon
[geek challenge 2019] PHP problem solving record
Three uses of golang underscores
In situ merging of two arrays with two pointers
Data recovery software easyrecovery15 Download
Querywrapper in mybaits plus
The first dark spring cup dnuictf
Use PHP to delete the specified text content in the file