Skip to content

Commit 159d3fd

Browse files
committed
Time: 28 ms (48.52%), Space: 8 MB (95.21%) - LeetHub
1 parent 86cf315 commit 159d3fd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
string frequencySort(string s) {
4+
int freq[128] = {};
5+
for(char c: s)
6+
freq[c]++;
7+
8+
sort(s.begin(), s.end(), [&freq](const auto &a, const auto &b) -> bool {
9+
if(freq[a] != freq[b])
10+
return freq[a] > freq[b];
11+
return a > b;
12+
});
13+
14+
return s;
15+
}
16+
};

0 commit comments

Comments
 (0)