题解 | #删除有序链表中重复的元素-I#

删除有序链表中重复的元素-I

https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79

#include <stdlib.h>
struct ListNode* deleteDuplicates(struct ListNode* head ) {
    if(!head || !head->next)
    {
        return head;
    }
    struct ListNode *temp,*pre;
    temp = head->next;
    pre = head;
    int flag = 0;
    while(temp)
    {
        if (temp->val==pre->val) {
            temp = temp->next;
            free(pre->next);
            pre->next = temp;
        }
        else {
            pre = temp;
            temp=temp->next;
        }
    }
    return head;

}

全部评论

相关推荐

06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务