My code to remove duplicates from unsorted linked list is giving me wrong answer.I have tried dry running it but still can’t find any error
Problem link:
Code:
Node * removeDuplicates( Node *head)
{
set<int> st;
Node* temp=head->next;
Node* newhead=new Node(head->data);
Node* newtemp=newhead;
st.insert(head->data);
while(temp!=NULL)
{
if(temp->data==*st.find(temp->data))
{
temp=temp->next;
continue;
}
newtemp->next=new Node(temp->data);
newtemp=newtemp->next;
st.insert(temp->data);
temp=temp->next;
}
return newhead;
}