Skip to content

Commit 14e9ee9

Browse files
update 23
1 parent 36f1bda commit 14e9ee9

File tree

1 file changed

+2
-3
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-3
lines changed

Diff for: src/main/java/com/fishercoder/solutions/_23.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import com.fishercoder.common.classes.ListNode;
44

5-
import java.util.Comparator;
65
import java.util.PriorityQueue;
76

87
public class _23 {
98
public static class Solution1 {
109
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);
1211

1312
for (ListNode node : lists) {
1413
if (node != null) {
@@ -21,10 +20,10 @@ public ListNode mergeKLists(ListNode[] lists) {
2120
while (!heap.isEmpty()) {
2221
ListNode curr = heap.poll();
2322
temp.next = new ListNode(curr.val);
23+
temp = temp.next;
2424
if (curr.next != null) {
2525
heap.offer(curr.next);
2626
}
27-
temp = temp.next;
2827
}
2928
return pre.next;
3029
}

0 commit comments

Comments
 (0)