美文网首页
83.Remove Duplicates from Sorted

83.Remove Duplicates from Sorted

作者: 花落花开花满天 | 来源:发表于2018-11-07 12:12 被阅读0次

    一个已排序的链表,删除重复数字。

    代码:

    ListNode* deleteDuplicates(ListNode* head) {

            if(head==NULL)

            return NULL;

        ListNode *pre=head,*cur=head->next;

        int num=head->val;

        while(cur!=NULL)

        {

            if(cur->val==num)

            {

                pre->next=cur->next;

            }

            else

            {

                pre=cur;

                num=cur->val;

            }

            cur=cur->next;

        }

        return head;

        }

    };

    相关文章

      网友评论

          本文标题:83.Remove Duplicates from Sorted

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