We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4d6b754 commit 7d94bf5Copy full SHA for 7d94bf5
java/0791-custom-sort-string.java
@@ -0,0 +1,22 @@
1
+class Solution {
2
+ public String customSortString(String order, String s) {
3
+ Map<Character, Integer> map = new HashMap<>();
4
+ for(char c: s.toCharArray())
5
+ map.put(c, map.getOrDefault(c, 0) + 1);
6
+
7
+ StringBuilder res = new StringBuilder();
8
+ for(char c: order.toCharArray()){
9
+ while(map.containsKey(c) && map.get(c) > 0){
10
+ res.append(c);
11
+ map.put(c, map.get(c)-1);
12
+ }
13
14
+ for(char c: map.keySet()){
15
+ while(map.get(c) > 0){
16
17
18
19
20
+ return res.toString();
21
22
+}
0 commit comments