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.
Here is my python solution. It passes all the test cases
defInsertNth(head,data,position):ifheadisNone:# position must be 0returnNode(data,None)ifposition==0:returnNode(data,head)prevNode=headfor_inrange(position-1):prevNode=prevNode.nextprevNode.next=Node(data,prevNode.next)returnhead
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
Here is my python solution. It passes all the test cases