023-merge_k_sorted_lists.md - 023 merge k sorted lists Merge k sorted linked lists and return it as one sorted list Analyze and describe its complexity

023-merge_k_sorted_lists.md - 023 merge k sorted lists...

This preview shows page 1 out of 1 page.

023 merge k sorted lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. ### 使用 STL PriorityQueue 方法实现 ```cpp /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode mergeKLists(ListNode[] lists) { if (lists == null || lists.length == 0){ return null; } int size = lists.length; Queue<ListNode> heap = new PriorityQueue(size, new ListNodeComparator());
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

  • Fall '17
  • Ms.Zhang

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes