当前位置:网站首页>Sorting by character frequency
Sorting by character frequency
2022-06-30 14:40:00 【Douglas_ LT】
A daily topic ing, Today is a day medium topic 451. Sort Characters By Frequency
class Solution {
public:
string frequencySort(string s) {
unordered_map<char, int> umap;
for (int i = 0; i < s.size(); i++) {
umap[s[i]]++;
}
priority_queue<pair<int, char>> pq;
for (auto p : umap) {
pq.push(pair<int, char>(p.second, p.first));
}
string ret;
int len = pq.size();
while (len--) {
auto p = pq.top();
int cnt = p.first;
char ch = p.second;
while (cnt--) {
ret.push_back(ch);
}
pq.pop();
}
return ret;
}
};
边栏推荐
- The first three passes of sqli Labs
- XSS challenge (6-10) more detailed answers
- Experiment 2: stack
- @Component use cases
- 【BUUCTF】 EasySql
- Realize a simple LAN communication (similar to feiqiu)
- Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package
- Error on datetime when importing SQL file from MySQL
- Pseudocode writing specification
- PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
猜你喜欢

Introduction to the construction and development of composer private warehouse
![[extensive reading of papers] multimodal attribute extraction](/img/ec/546c107ac0d31deded7ca94fdf0e2d.jpg)
[extensive reading of papers] multimodal attribute extraction

Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit

Notes on reverse learning in the first week of winter vacation

The first three passes of sqli Labs

Knowledge learned from the water resources institute project

Detailed explanation of settimeout() and setinterval()

Getting started with shell Basics

ctfshow nodejs

Zend studio how to import an existing project
随机推荐
Getting started with shell Basics
Introduction to the construction and development of composer private warehouse
[extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
2021-08-07 native and package types
Use PHP to delete the specified text content in the file
JMeter transaction controller
Notes on reverse learning in the first week of winter vacation
Component communication mode
Att & CK red team evaluation field (I)
Judgment of deep learning experiment results
PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available
Lihongyi machine learning 2020 homework summary
Crypto questions
Thinkphp5 log file contains trick
Querywrapper in mybaits plus
LIS error: this configuration section cannot be used in this path
Initial attack and defense world Misc
After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs
An error is reported when installing dataspherestudio doc: invalid default value for 'update_ time‘
Greedy interval problem (5)