Accepted Simple C Solution (5ms)


  • 0
    struct ListNode* deleteDuplicates(struct ListNode* head)
    {
        int k = 0;
        struct ListNode* h=malloc(sizeof(struct ListNode)), *y = head;
        struct ListNode* p = h;
    
       while(y&&y->next)
       {
          if(y->val == y->next->val)
          {
             k = y->val;
             while(y&&y->val==k) y=y->next;
          } else {
             h->next = y;
             h = h->next;
             y = y->next;
          }
     }
    
     if(y)
       h->next = y;
     else
       h->next = NULL;
     return p->next;;
    }

Log in to reply
 

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