Remove duplicates from sorted LL
void removeDuplicates(struct node* head)
{
struct node* current = head;
struct node* next;
if(current == NULL)
return;
while(current->next!= NULL)
{
if(current->data == current->next->data)
{
next=current->next->next;
free(current->next);
current->next=next;
}
else
{
current = current->next;
}
}
}
Time Complexity: O(n)
{
struct node* current = head;
struct node* next;
if(current == NULL)
return;
while(current->next!= NULL)
{
if(current->data == current->next->data)
{
next=current->next->next;
free(current->next);
current->next=next;
}
else
{
current = current->next;
}
}
}
Time Complexity: O(n)
Comments
Post a Comment