2
* Definition for singly-linked list.5
* next: ListNode | null6
* constructor(val?: number, next?: ListNode | null) {7
* this.val = (val===undefined ? 0 : val)8
* this.next = (next===undefined ? null : next)13
function insertionSortList(head: ListNode | null): ListNode | null {14
if (!head) return null15
if (!head.next) return head23
const next = curr.next24
const insertion = curr26
output = insert(output, insertion)27
curr = next as ListNode33
function insert(head: ListNode, other: ListNode) {37
if (val <= head.val) {43
if ((val > curr.val && curr.next && val <= curr.next.val) || !curr.next) {44
other.next = curr.next50
curr = curr.next as ListNode