Skip to content

Commit 42d8436

Browse files
committed
Runtime: 22 ms (Top 36.06%) | Memory: 8.5 MB (Top 65.22%)
1 parent 8a6ce52 commit 42d8436

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
// Runtime: 22 ms (Top 36.06%) | Memory: 8.5 MB (Top 65.22%)
12
class Solution {
23
public:
3-
string frequencySort(string s)
4+
string frequencySort(string s)
45
{
56
unordered_map<char,int>mp;
6-
for(int i=0;i<s.length();i++) //get the frequency of every char of the string
7+
for(int i=0;i<s.length();i++) //get the frequency of every char of the string
78
{
89
mp[s[i]]++;
910
}
10-
11-
priority_queue<pair<int,char>>pq; //store the freq and char pair in max heap
11+
12+
priority_queue<pair<int,char>>pq; //store the freq and char pair in max heap
1213
for(auto it=mp.begin();it!=mp.end();it++)
1314
{
1415
pq.push({it->second,it->first});
@@ -17,15 +18,14 @@ class Solution {
1718
int val;
1819
while(!pq.empty())
1920
{
20-
val=pq.top().first; //append the char frequency times
21+
val=pq.top().first; //append the char frequency times
2122
while(val--)
2223
{
2324
str.push_back(pq.top().second);
2425
}
2526
pq.pop();
2627
}
2728
return str;
28-
29-
}
30-
};
3129

30+
}
31+
};

0 commit comments

Comments
 (0)