File tree 1 file changed +2
-3
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +2
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import com .fishercoder .common .classes .ListNode ;
4
4
5
- import java .util .Comparator ;
6
5
import java .util .PriorityQueue ;
7
6
8
7
public class _23 {
9
8
public static class Solution1 {
10
9
public ListNode mergeKLists (ListNode [] lists ) {
11
- PriorityQueue <ListNode > heap = new PriorityQueue (( Comparator < ListNode >) ( o1 , o2 ) -> o1 .val - o2 .val );
10
+ PriorityQueue <ListNode > heap = new PriorityQueue <>(( a , b ) -> a .val - b .val );
12
11
13
12
for (ListNode node : lists ) {
14
13
if (node != null ) {
@@ -21,10 +20,10 @@ public ListNode mergeKLists(ListNode[] lists) {
21
20
while (!heap .isEmpty ()) {
22
21
ListNode curr = heap .poll ();
23
22
temp .next = new ListNode (curr .val );
23
+ temp = temp .next ;
24
24
if (curr .next != null ) {
25
25
heap .offer (curr .next );
26
26
}
27
- temp = temp .next ;
28
27
}
29
28
return pre .next ;
30
29
}
You can’t perform that action at this time.
0 commit comments