File tree 1 file changed +18
-17
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +18
-17
lines changed Original file line number Diff line number Diff line change 12
12
* Analyze and describe its complexity.*/
13
13
14
14
public class _23 {
15
-
16
- public ListNode mergeKLists (ListNode [] lists ) {
17
- PriorityQueue <ListNode > heap = new PriorityQueue ((Comparator <ListNode >) (o1 , o2 ) -> o1 .val - o2 .val );
18
-
19
- for (ListNode node : lists ) {
20
- if (node != null ) {
21
- heap .offer (node );
15
+ public static class Solution1 {
16
+ public ListNode mergeKLists (ListNode [] lists ) {
17
+ PriorityQueue <ListNode > heap = new PriorityQueue ((Comparator <ListNode >) (o1 , o2 ) -> o1 .val - o2 .val );
18
+
19
+ for (ListNode node : lists ) {
20
+ if (node != null ) {
21
+ heap .offer (node );
22
+ }
22
23
}
23
- }
24
24
25
- ListNode pre = new ListNode (-1 );
26
- ListNode temp = pre ;
27
- while (!heap .isEmpty ()) {
28
- ListNode curr = heap .poll ();
29
- temp .next = new ListNode (curr .val );
30
- if (curr .next != null ) {
31
- heap .offer (curr .next );
25
+ ListNode pre = new ListNode (-1 );
26
+ ListNode temp = pre ;
27
+ while (!heap .isEmpty ()) {
28
+ ListNode curr = heap .poll ();
29
+ temp .next = new ListNode (curr .val );
30
+ if (curr .next != null ) {
31
+ heap .offer (curr .next );
32
+ }
33
+ temp = temp .next ;
32
34
}
33
- temp = temp .next ;
35
+ return pre .next ;
34
36
}
35
- return pre .next ;
36
37
}
37
38
38
39
}
You can’t perform that action at this time.
0 commit comments