• + 0 comments
    Node* removeDuplicates(Node *head)
    {
     //Write your code here
     if (nullptr == head)
      return head;
               
     Node* pNode = head;     
     while(nullptr != pNode)
     {
      if (nullptr != pNode->next && pNode->data == pNode->next->data)
      {
       Node* toDelete = pNode->next;
       pNode->next = pNode->next->next;
       delete toDelete; // to not leak memory
       continue; // for triplets or more
      }
                    
      pNode = pNode->next;
     }
                
     return head;
    }