Merge-K-Sorted-Lists
Updated:
Contents
/*
- Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
/
/* - Definition for singly-linked list.
- public class ListNode {
- int val;
- ListNode next;
- ListNode(int x) {
- val = x;
- next = null;
- }
- }
*/
- 把每个 List 和List 进行 Merge,再重复
1 | class Solution { |
- 先把每个 List 的第一个节点放进优先队列,每次取出队列中的最大值节点,再把那个节点的 next 放进去。
1 | public class Solution { |