/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
*/
public class Solution {
public ListNode mergeKLists(List<ListNode> lists) {
ListNode head=new ListNode(-1);
ListNode tail=head;
if(lists.size()<=0) return null;
Comparator<ListNode> mycmp=new Comparator<ListNode>()
{
public int compare(ListNode l1,ListNode l2)
{
if(l1.val>l2.val) return 1;
else if(l1.val<l2.val)return -1;
return 0; } } ; PriorityQueue<ListNode> prq=new PriorityQueue<ListNode>(lists.size(),mycmp);
for(ListNode n:lists)
{
if(n!=null)
{
prq.add(n);
} }
while(prq.size()>0)
{
ListNode tem=prq.poll();
tail.next=tem;
tail=tail.next;
if(tem.next!=null)
{
prq.add(tem.next);
} } return head.next; }
}

(java) Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.的更多相关文章

  1. Data Structure Linked List: Merge Sort for Linked Lists

    http://www.geeksforgeeks.org/merge-sort-for-linked-list/ #include <iostream> #include <vect ...

  2. Java for LeetCode 023 Merge k Sorted Lists

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 解 ...

  3. Merge k Sorted Lists Leetcode Java

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 使 ...

  4. Java [leetcode 23]Merge k Sorted Lists

    题目描述: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complex ...

  5. 23. Merge k Sorted Lists (JAVA)

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. E ...

  6. 23. Merge K Sorted Lists (Java, 归并排序的思路)

    题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity ...

  7. No.023:Merge k Sorted Lists

    问题: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexit ...

  8. LeetCode——Merge k Sorted Lists

    Discription: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its ...

  9. leetcode -- Merge k Sorted Lists add code

    Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. [ ...

随机推荐

  1. POJ 2039 To and Fro(模拟)

    To and Fro Description Mo and Larry have devised a way of encrypting messages. They first decide sec ...

  2. ZOJ 1234 Chopsticks(动态规划)

    Chopsticks 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=234 题目大意:给定n个筷子的长度,取k+8套筷 ...

  3. Linux的more、less

    2.more 文件内容或输出查看工具: more 是我们最常用的工具之一,最常用的就是显示输出的内容,然后根据窗口的大小进行分页显示,然后还能提示文件的百分比: de>[root@localho ...

  4. 调整ListBox控件的行间距及设置文本格式

    首先要将该控件的DrawMode属性为OwnerDrawVariable 添加DrawItem重绘事件:private void listBox1_DrawItem(object sender, Dr ...

  5. Javascript线程及定时机制

    setTimeout.setInterval的使用 Javascript api文档中定义setTimeout和setInterval第二个参数意义分别为间隔多少毫秒后回调函数被执行和每隔多少毫秒回调 ...

  6. Centos6.5安装

    前奏:CentOS 6.5下载地址http://mirror.centos.org/centos/6.5/isos/x86_64/CentOS-6.5-x86_64-bin-DVD1to2.torre ...

  7. Ext.String 方法

    1.Ext.String.htmlEncode(value); 编码字符串,对其中特殊字符进行转义 xt.String.htmlEncode("hello'world"); //& ...

  8. C++11老关键字的新含义(auto, using,extern)

    http://blog.csdn.net/cnsword/article/details/8034947 公司可以使用c++11.看大牛的代码模仿使用,所以现在已经不知道什么使用的是c++的语法还是c ...

  9. Objective-C的反射

          我第一次接触Java的时候就觉得整个反射包都很新颖,它使得Java和解释型的脚本语言更接近了,与此同时也拉开了和主流的C和C++的距离.在运行时可以窥视到一个对象的类元数据真的很不可思议, ...

  10. xfire实现webservice客户端之测试关注点

    日前的工作接触到很多系统间的Webservice调用,这里想谈谈基于spring+xfire实现的webservice的客户端踩过的一些坑,需要测试关注的点. xFire的配置项 在spring中实现 ...