You are viewing a single comment's thread. Return to all comments →
I got almost the same answer. There is a small improvement to be had.
def insertNodeAtPosition(head, data, position): n = head for _ in range(position - 1): n = n.next n_next = n.next n.next = SinglyLinkedListNode(data) n.next.next = n_next return head
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
I got almost the same answer. There is a small improvement to be had.