Skip to content

Add solution #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Solution
  • Loading branch information
xdongyan committed Aug 8, 2017
commit f781d8d76ca60a6ac4e9ab293ad7f1322583e621
6 changes: 3 additions & 3 deletions src/main/java/com/fishercoder/solutions/_451.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public class _451 {
public String frequencySort(String s) {
Map<Character, Integer> map = new HashMap();
for (char c : s.toCharArray()) map.put(c, map.getOrDefault(c, 0) + 1);
List<Map.Entry<Character, Integer>> list = new ArrayList<>(map.entrySet());
Collections.sort(list, (o1, o2) -> (o2.getValue()).compareTo(o1.getValue()));
StringBuilder stringBuilder = new StringBuilder();
List<Map.Entry<Character, Integer>> list = new ArrayList<>(map.entrySet());
Collections.sort(list, (o1, o2) -> (o2.getValue()).compareTo(o1.getValue()));
StringBuilder stringBuilder = new StringBuilder();
for (Map.Entry<Character, Integer> entry : list) {
for (int i = 0; i < entry.getValue(); i++) {
stringBuilder.append(entry.getKey());
Expand Down