funmergeKLists(lists: Array<ListNode?>): ListNode? { val listArray = ArrayList<ListNode>() for (node in lists){ if (node!=null) listArray.add(node) } if (listArray.isEmpty()) returnnull val listHead = ListNode(0) var listCurrent = listHead while (listArray.isNotEmpty()){ var num = listArray[0].`val` var index = 0 for (i in1 until listArray.size){ if (listArray[i].`val`<=num){ num = listArray[i].`val` index = i } } listCurrent.next = listArray[index] listCurrent = listCurrent.next!! if (listArray[index].next!=null) listArray[index] = listArray[index].next!! else listArray.removeAt(index) } listCurrent.next = null return listHead.next }