Node * removeDuplicates(Node *head){
// Write your code here
Node *temp = head;
Node *temp2 = head->next;
while(temp2 != nullptr){
if(temp2->data == temp->data){
while(temp2->data == temp->data){
if(temp2->next == nullptr){
temp->next->prev = nullptr;
temp->next = nullptr;
break;
}
temp2 = temp2->next;
continue;
}
if(temp->next == nullptr) break;
temp->next = temp2;
temp2->prev = temp;
temp = temp->next;
temp2 = temp2->next;
}
else{
temp = temp->next;
temp2 = temp2->next;
}
}
return head;
}