# Remove duplicates from list

Almost the same as the first one, but this time we will simply delete duplicates such that each number only appear once.

After the while loop, we will just move slow forward once so it points to the first of many( >= 2) duplicates and points slow -> next to the next unique number.

``````/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* fast;
ListNode* slow;
ListNode dummyNode(-1);
slow = &dummyNode;

while(fast && fast -> next != NULL){
if(fast -> next -> val == slow -> next -> val ){
while(fast -> next && fast -> next -> val == slow -> next -> val){
fast = fast -> next;
}
slow = slow -> next;
slow -> next = fast -> next;
fast = fast -> next;

}
else{
fast = fast ->next;
slow = slow -> next;

}
}
return dummyNode.next;
}
};
``````

# A simpler method

We will just use one pointer

``````/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
while(curr && curr -> next){
if(curr ->next ->val == curr ->val){
curr -> next = curr->next->next;
}
else
curr = curr->next;
}
}

};
``````

# Recursive

We use a helper function that will iterate through the linked list and will skip duplicates.

``````/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
}