A very simple c/c++ solution I think it is my pain, because I failed my interview using the likely methon

  • 0
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode **linkp = &head;
        ListNode *cur;
        while((cur = *linkp) != NULL){
            int val = cur->val;
            if(cur->next && cur->next->val == val){
                while(cur && cur->val == val){  //Remove Duplicates
                    ListNode *p = cur;
                    cur = cur->next;
                *linkp = cur;
            }else{                                //no  Duplicates
                linkp = &cur->next;
        return head;

  • 0

    Why would this method fail in an interview?

Log in to reply

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