var mergeKLists = function (lists) { let listarr = newListNode(0); let head = listarr; let end = true; while (end) { let min = Infinity; let pos = null; for (let i = 0; i < lists.length; i++) { if (lists[i] != null) { if (min > lists[i].val) { pos = i; min = lists[i].val; } } } if (pos != null) { head.next = lists[pos]; lists[pos] = lists[pos].next; head = head.next; } if (min == Infinity) { end = false; } } return listarr.next; };