Solution - C++ O(1) space and O(n) time


#1
ListNode* Solution::deleteDuplicates(ListNode* head) 
{
    ListNode* temp = head;
    ListNode* tail = head;
    while(temp)
    {
        if(tail->val == temp->val)
        {
            temp = temp->next;
        }
        else
        {
            tail->next = temp;
            tail = tail->next;
            // temp->next = NULL;
            temp = temp->next;
        }
    }
    tail->next = NULL;
    return head;
}