给你一个链表数组,每个链表都已经按升序排列。
请你将所有链表合并到一个升序链表中,返回合并后的链表。
class Solution {
public ListNode mergeKLists(ListNode[] lists) {
int n = lists.length;
ListNode res = null;
for(int i=0; i j.val){
cur.next = j;
j = j.next;
}else{
cur.next = i;
i = i.next;
}
cur = cur.next;
}
cur.next = i==null ? j:i;
return head.next;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)