public ListNode mergeKLists(ArrayList<ListNode> lists) {
        if(lists == null || lists.size() == 0) return null;
        for(int k = 1; k < lists.size(); k = k * 2) {
            for(int i = 0; i + k < lists.size(); i = i + k * 2) {
                lists.set(i, merge(lists.get(i), lists.get(i+k)));
            }
        }
        return lists.get(0);
    }