Simple C++ Solution with O(n) time and O(1) space


#1
ListNode* Solution::deleteDuplicates(ListNode* A) {
    if(A->next==NULL) return A;
    ListNode*prev=A;
    ListNode*cur=A->next;
    while(cur){
        if(prev->val==cur->val){
            cur=cur->next;
            prev->next=cur;
        }
        else{
            cur=cur->next;
            prev=prev->next;
        }
    }
    return A;
}