Skip to content

Commit f7dbe39

Browse files
committed
Time: 27 ms (51.76%), Space: 8.8 MB (19.08%) - LeetHub
1 parent dd7dd7f commit f7dbe39

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
string frequencySort(string s) {
4+
unordered_map<char,int> mp;
5+
6+
for(auto itr : s)
7+
++mp[itr];
8+
9+
priority_queue<pair<int,char>> pq;
10+
for(auto itr : mp)
11+
pq.push({itr.second,itr.first});
12+
13+
string ans;
14+
15+
while(!pq.empty())
16+
{
17+
ans += string(pq.top().first,pq.top().second);
18+
pq.pop();
19+
}
20+
21+
return ans;
22+
}
23+
};

0 commit comments

Comments
 (0)