[Leetcode] 23. Merge k Sorted Lists

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

/**
* 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;
}

return merge(lists, 0, lists.length);
}

public ListNode merge(ListNode[] lists,int low, int high){
int n = high - low;
if(n < 1){
return null;
}
if(n == 1){
return lists[low];
}
int mid = low + n / 2;

ListNode left = merge(lists,low, mid);
ListNode right = merge(lists,mid, high);

return MegerList(left,right);
}

//  对两个已排序的链表进行合并

}
else{
}
p = p.next;
}

}
}

}
}

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

2016-06-04 00:46:59

LeetCode 23 Merge k Sorted Lists（合并K个已排序链表）

2015-11-12 17:30:10

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

2015-03-05 11:19:11

LeetCode 23： Merge K Sorted Lists

2015-05-31 02:04:42

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

2015-05-11 15:39:00

[Leetcode]23. Merge k Sorted Lists @python

2016-01-16 15:32:14

LeetCode(23)Merge K Sorted Lists

2013-12-21 16:27:23

LeetCode Merge k Sorted Lists 解题报告

2014-10-11 15:23:24

23. Merge k Sorted Lists 优先队列 比较器

2016-11-17 22:35:23

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

2017-04-07 10:32:55

不良信息举报

[Leetcode] 23. Merge k Sorted Lists