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.
publicstaticSinglyLinkedListNodedeleteNode(SinglyLinkedListNodellist,intposition){// Write your code here//? If the position is pointing at address 0, go next on the main pointer.if(position==0){llist=llist.next;returnllist;}//? Make instance of 2 pointers.SinglyLinkedListNodepointer=llist;//? Pointer 1.SinglyLinkedListNodesecondPointer=llist;//? Pointer 2.//? Get the address of the pointer after the address that's going to be deleted.for(inti=0;i<position+1;i++){pointer=pointer.next;}//? Get the address of the pointer before the specified deletion address.for(inti=0;i<position-1;i++){secondPointer=secondPointer.next;}//? Use the second pointer to replace the .next address with pointer 1's address.secondPointer.next=pointer;returnllist;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Delete a Node
You are viewing a single comment's thread. Return to all comments →
Solution with 2 pointers using Java.