remove dumplicate from a sorted list in O(N) in cpp/c++
Intuitioneasy methode in O(N)Approachsimple while loop
there is two case
if temporary node next has same value  as temp value then store it and  then again do a
# Intuition
easy methode in O(N)

# Approach
simple while loop 
there is two case 
1) if temporary node next has same value  as temp value then store it and  then again do a while loop till temp val not equal to stored val and then prev->next = temp
2) else prev = temp or temp temp->next 

# Complexity
- Time complexity:
O(N)

- Space complexity:
O(1)

# Code
```cpp []
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(head==nullptr||head->next==nullptr)return head;
        ListNode* temp = head;
        ListNode* dummy = new ListNode(-1);
        ListNode* prev = dummy ;
        prev->next = head;
        while(temp!=nullptr&&temp->next!=nullptr){
            if(temp->next->val==temp->val){
                int v = temp->val;
                while(temp!=nullptr){
                    if(temp->val==v)temp = temp->next;
                    else break ;
                }
                prev->next = temp;
            }
            else{
                prev = temp ;
                temp = temp->next;
            }
        }
        return dummy->next;
    }
};
```
['C++']