23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
Example:
Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4->4->5->6 题意:按大小顺序合并n条链表 代码如下:
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } *//** * @param {ListNode[]} lists * @return {ListNode} */var mergeKLists = function(lists) { if(lists.length===0) return null; var n=lists.length; while(n>1){ var k=parseInt((n+1)/2); for(var i=0;i