23. Merge k Sorted Lists [H] k merge sort list

topic


Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
Example:
 Input:
 [
  1->4->5,
  1->3->4;
  2->6
 ]
 Output:1->1->2->3->4->4->5->6

Thinking


1 idea: heapsort

  • The minimum heap
  • Priority Queue

    Ideas 2: sub-rule of law

Tips


1. Small heap top

1.1 Maintenance top small heap property
1.2 build small pile top

2. Priority Queue

3. The rule of law points

C++

Python

reference

[1] Introduction to Algorithms Chapter VI

Guess you like

Origin www.cnblogs.com/Jessey-Ge/p/10993528.html