public ListNode mergeKLists(ArrayList<ListNode> lists) {
    	if (lists == null || lists.size() == 0)
    		return null;    
    	
    	PriorityQueue<ListNode> queue = 
                new PriorityQueue<ListNode>(lists.size(), new ListNodeComparator());
    	for (ListNode n : lists)
    		if (n != null)
    			queue.offer(n);
    	
    	ListNode head = null;
    	ListNode tail = null;
    	while (queue.isEmpty() == false)
    	{
    		if (head == null)
    			head = tail = queue.poll();
    		else
    		{
    			tail.next = queue.poll();
    			tail = tail.next;
    		}
    		if (tail.next != null)
    			queue.offer(tail.next);
    	}
    		
    	return head;
    }