Leetcode 移除链表重复节点 c

C版,不使用缓存区

typedef struct ListNode ListNode;

// 1 1 2 3
struct ListNode* removeDuplicateNodes(struct ListNode* head){
    if(head==NULL||head->next==NULL){
          return head;
    }
    ListNode *cur=head;
    ListNode *pre=NULL;
    ListNode *next=NULL;
    
    while(cur) {
        pre=cur;
        next=cur->next;
        while(next){
            if(cur->val==next->val) {
                pre->next=next->next;
            }else{
                pre=next;
            }
            next=next->next;
        }
        cur=cur->next;
    }
    return head;
}
发布了40 篇原创文章 · 获赞 12 · 访问量 860

猜你喜欢

转载自blog.csdn.net/qq_29334605/article/details/105388548