美文网首页
Remove Duplicates from Sorted Li

Remove Duplicates from Sorted Li

作者: 无云清晨 | 来源:发表于2017-12-26 11:40 被阅读0次
    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     struct ListNode *next;
     * };
     */
    struct ListNode* deleteDuplicates(struct ListNode* head)
     {
        if(NULL == head)
          return NULL;
        struct ListNode* p = head;
        struct ListNode* q = head->next;
        int val1 = p->val;
        int val2;
        while(q != NULL)
        {
           val2 = q->val;
           if(val2 == val1)
           {
             q = q -> next;
    
             if(q == NULL)
             {
              p->next = q;
             }
    
          }
    
           else
           {
             val1 = val2;
             p ->next = q;
             p = q;
             q = q -> next;
           }
        }
        return head;
     }
    

    相关文章

      网友评论

          本文标题:Remove Duplicates from Sorted Li

          本文链接:https://www.haomeiwen.com/subject/clvdgxtx.html