To insert a new node after a given node prev: pseudocode newNode = new ListNode(val) newNode.next = prev.next prev.next = newNode Order matters here. If you set prev.next = newNode first, you lose the reference to the rest of the list.
Inserting at the head is a special case: ```pseudocode newNode = new ListNode(val) newNode.next = head head = newNode
Finding that point might take $O(n)$. Time: $O(n)$. Space: $O(1)$.