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

src/main/java/com/fishercoder/solutions/_23.java

Lines changed: 2 additions & 3 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy