23. Merge k Sorted Lists

使用归并

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode mergeKLists(ListNode[] lists) {
        if(lists.length==0)return null;
        if(lists.length==1)return lists[0];
        return merge(lists,0,lists.length-1);
    }
    public ListNode merge(ListNode[] lists,int low,int high){
        if(high==low){
            return lists[high];          
        }
        if(high-low==1)
            return merge2Lists(lists[low],lists[high]);
        if(high

你可能感兴趣的:(23. Merge k Sorted Lists)