# [LeetCode][Java] Merge k Sorted Lists

## 题目：

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

## AC代码：

/**
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) { val = x; }
* }
*/
//合并为一个数组，排序，再转化为ListNode
public class Solution
{
public ListNode mergeKLists(ListNode[] lists)
{
ArrayList<Integer> alist= new ArrayList<Integer>();
ListNode res=null;

if(lists==null||lists.length==0) return res;

for(int i=0;i<lists.length;i++)
{
ListNode temlist=lists[i];
while(temlist!=null)
{
temlist=temlist.next;
}
}
Collections.sort(alist);
if(alist.size()==0)
return res;
else
{
res=new ListNode(alist.get(0));
for(int i=0;i<alist.size()-1;i++)
{
res.next=new ListNode(alist.get(i+1));
res=res.next;
}
}
}
}

• 本文已收录于以下专栏：

## [LeetCode] 023. Merge k Sorted Lists (Hard) (C++/Java/Python)

[LeetCode] 023. Merge k Sorted Lists (Hard) (C++/Java/Python)
• hcbbt
• 2015年03月05日 11:19
• 2467

## LeetCode 23 Merge k Sorted Lists (C,C++,Java,Python)

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

## 【LeetCode】23. Merge k Sorted Lists 基于Java的解法

23. Merge k Sorted Lists Total Accepted: 88102 Total Submissions: 372066 Difficulty: Hard Merge k...

## [LeetCode] 23. Merge k Sorted Lists java

/**23. Merge k Sorted Lists * @param lists * @return 合并k路有序链表 */ public ListNode ...

## [Leetcode] Merge k Sorted Lists (Java)

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

## 【LeetCode-面试算法经典-Java实现】【023-Merge k Sorted Lists（合并k个排好的的单链表）】

【023-Merge k Sorted Lists（合并k个排好的的单链表）】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题　　Merge k sorted linked l...

## leetcode解题之23.Merge k Sorted Lists Java版本（合并k个有序的链表）

leetcode解题之23.Merge k Sorted Lists Java版本（合并k个有序的链表）

## [LeetCode]Merge k Sorted Lists

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

## leetcode23~Merge k Sorted Lists Add to List

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

## 【leetcode】23. Merge k Sorted Lists

举报原因： 您举报文章：[LeetCode][Java] Merge k Sorted Lists 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)