From 07f986e8035bfa12d38a33438ba0517fe716b451 Mon Sep 17 00:00:00 2001 From: HardikG14 <96937322+HardikG14@users.noreply.github.com> Date: Sun, 27 Mar 2022 11:57:01 +0530 Subject: [PATCH] another recursive code --- LL-1/Eliminate duplicates from LL | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/LL-1/Eliminate duplicates from LL b/LL-1/Eliminate duplicates from LL index 638bc51..76603f3 100644 --- a/LL-1/Eliminate duplicates from LL +++ b/LL-1/Eliminate duplicates from LL @@ -21,6 +21,18 @@ node* eliminate_duplicate(node* head) --------------------------------------------------------------------------- // recursively +node* removeDup(node* head){ + if(head==nullptr || head->next==nullptr){ + return head; + } + node* smallAns = removeDup(head->next); + if(smallAns->Data == head->data){ + delete head; + return smallAns; + } + head->next = smallAns; + return head; +} SinglyLinkedListNode* removeDuplicates(SinglyLinkedListNode* head) { if(head==NULL || head->next == NULL)