Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 557b7e0

Browse filesBrowse files
authored
Merge pull request AlgoStudyGroup#123 from QianHx/master
A simple Java version
2 parents 5356089 + 45451a6 commit 557b7e0
Copy full SHA for 557b7e0

File tree

Expand file treeCollapse file tree

1 file changed

+27
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-0
lines changed
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public String frequencySort(String s) {
3+
StringBuilder S = new StringBuilder();
4+
int table[] = new int[128];
5+
for(int i=0; i<s.length(); ++i){
6+
++table[s.charAt(i)];
7+
}
8+
9+
int max = 0;
10+
int temp = table[max];
11+
do {
12+
max = 0;
13+
temp = table[max];
14+
for(int j=0; j<128; ++j){
15+
if(table[j]> temp){
16+
max = j;
17+
temp = table[max];
18+
}
19+
}
20+
for(int k=temp; k>0; --k){
21+
S.append((char)max);
22+
}
23+
table[max] = 0;
24+
} while(temp != 0);
25+
return S.toString();
26+
}
27+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.