File tree 1 file changed +1
-23
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +1
-23
lines changed Original file line number Diff line number Diff line change 6
6
import java .util .PriorityQueue ;
7
7
import java .util .Queue ;
8
8
9
- /**
10
- * 358. Rearrange String k Distance Apart
11
- *
12
- * Given a non-empty string s and an integer k, rearrange the string such that the same characters are at least distance k from each other.
13
-
14
- All input strings are given in lowercase letters. If it is not possible to rearrange the string, return an empty string "".
15
- Example 1:
16
- s = "aabbcc", k = 3
17
- Result: "abcabc"
18
- The same letters are at least distance 3 from each other.
19
-
20
- Example 2:
21
- s = "aaabc", k = 3
22
- Answer: ""
23
- It is not possible to rearrange the string.
24
-
25
- Example 3:
26
- s = "aaadbbcc", k = 2
27
- Answer: "abacabcd"
28
- Another possible answer is: "abcabcda"
29
- The same letters are at least distance 2 from each other.
30
- */
31
9
public class _358 {
32
10
33
11
public static class Solution1 {
@@ -38,7 +16,7 @@ public String rearrangeString(String s, int k) {
38
16
}
39
17
40
18
PriorityQueue <Map .Entry <Character , Integer >> heap =
41
- new PriorityQueue <>((a , b ) -> b .getValue () - a .getValue ());
19
+ new PriorityQueue <>((a , b ) -> b .getValue () - a .getValue ());
42
20
heap .addAll (count .entrySet ());
43
21
44
22
Queue <Map .Entry <Character , Integer >> waitQueue = new LinkedList <>();
You can’t perform that action at this time.
0 commit comments