4ms c solution with pointers-to-pointers


  • 0
    E
    struct ListNode *deleteDuplicates(struct ListNode *head) {
        if(head){
            struct ListNode **curr = &head->next;
            int tmp = head->val;
            while(*curr) {
                struct ListNode *entry = *curr;
                if(tmp == entry->val) {
                    *curr = entry->next;
                     free(entry);
                } else {
                    tmp = entry->val;
                    curr = &entry->next;
                }
            }
        }
        return head;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.