Delete duplicate-value nodes from a sorted linked list

  • + 0 comments

    Here, my solution:

    SinglyLinkedListNode* removeDuplicates(SinglyLinkedListNode* llist) {
        SinglyLinkedListNode* prev;
        SinglyLinkedListNode* curr = llist;
        
        while(curr != NULL) {
            prev = curr;
            curr = curr->next;
            
            while(curr != NULL && curr->data == prev->data){
                prev->next = curr->next;
                curr = curr->next;
            }
        }
        
        return llist;
    }