We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def insertNodeAtPosition(head, data, position):
n = head #set variable n to equal head
for _ in range(position - 1):
n = n.next #loop thru llist until you get to desired position
n_next = n.next #set variable n_next to equal the next node
n.next = SinglyLinkedListNode(data) #set the next position as the new number
n.next.next = n_next #and the one after that as what used to be n.next
return head
Cookie support is required to access HackerRank
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 will try my best.