Skip to main content

Delete duplicate-value nodes from a sorted linked list-Hackerrank Solution

Problem

You are given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete nodes and return a sorted list with each distinct value in the original list. The given head pointer may be null indicating that the list is empty.

Solution:

/*

 * Complete the 'removeDuplicates' function below.

 *

 * The function is expected to return an INTEGER_SINGLY_LINKED_LIST.

 * The function accepts INTEGER_SINGLY_LINKED_LIST llist as parameter.

 */


/*

 * For your reference:

 *

 * SinglyLinkedListNode {

 *     int data;

 *     SinglyLinkedListNode* next;

 * };

 *

 */


SinglyLinkedListNode* removeDuplicates(SinglyLinkedListNode* llist) {

    

    SinglyLinkedListNode* temp=llist;

    SinglyLinkedListNode* tem=llist;

    SinglyLinkedListNode* del=llist;

    while (temp->next!=NULL) {

        if(temp->data==temp->next->data)

        {

            del=temp->next;

            temp->next=del->next;

            delete del;

            

        }

        else {

        temp=temp->next;


        }

    }

    return tem;


}




Comments

Popular posts from this blog

full video source

TO GET MEGA STEPS TO ACCESS THE THE Mega  1) Open  the below link in your browser 👆You have to disable your adbloker  2) Select The Box "I Am Not A Robot" , if it asks  3) Wait for 5  seconds and click Free access with ads (dont join premium)                                                 CLICK HERE TO GET LINK    4) Click "Discover Articles" & Wait For 5 Seconds After That Click On The X  5) Click "Related Topics" & Wait For 5 Seconds After That Click On The X For the app download part,if it asks , click to download the app  and when redirected just go back and wait 1 minute you don’t have to download it ,after that minute you will see the tick mark  appear .(YOU DON'T HAVE TO DOWNLOAD ANYTHING)  6) Click On Continue That's it enjoy your mega link 👍 NOTE👉All links are FREE & NO SPAM. The reaso...

FULL VIDEO SOURCE

  CLICK HERE  JESSA RHODES FULL COLLECTION         EMILY LYNN CLICK HERE LINK FULL VIDEO CLICK HERE TO GET HENTAI LINK STEPS TO ACCESS THE THE Mega 1) Open the link in your browser 👆You have to disable your adbloker 2) Select The Box "I Am Not A Robot" , if it asks 3) Wait for 5 seconds and click Free access with ads (dont join premium) 4) Click "Discover Articles" & Wait For 5 Seconds After That Click On The X 5) Click "Related Topics" & Wait For 5 Seconds After That Click On The X For the app download part,if it asks , click to download the app and when redirected just go back and wait 1 minute you don’t have to download it ,after that minute you will see the tick mark appear .(YOU DON'T HAVE TO DOWNLOAD ANYTHING) 6) Click On Continue That's it enjoy your mega link 👍 NOTE👉All links are FREE & NO SPAM. The reason you have to go through this is to support me and prevent the website from getting banned. Thank you 😊.

MEGA COLLECTION FREE

  CLICK HERE ASIAN COLLECTION  TO GET MEGA STEPS TO ACCESS THE THE Mega  1) Open  the below link in your browser 👆You have to disable your adbloker  2) Select The Box "I Am Not A Robot" , if it asks  3) Wait for 5  seconds and click Free access with ads (dont join premium)   🔥CLICK HERE  Mulan Vuitton 🔥                             CLICK HERE BRAZZERS PPREMIUM         💯CLICK HERE  HollyWood Celebs 16GB INCLOUD LEAKS RARE COLLECTION 💯                                                            4) Click "Discover Articles" & Wait For 5 Seconds After That Click On The X  5) Click "Related Topics" & Wait For 5 Seconds After That Click On The X For the app download part,if it asks ...