本文共 539 字,大约阅读时间需要 1 分钟。
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* deleteDuplicates(struct ListNode* head) { struct ListNode* ret = head; if(!head) return ret; while(head->next) { if(head->next->val == head->val) { if(head->next->next) head->next = head->next->next; else head->next = NULL; } else { head = head->next; } }
转载地址:http://lzufb.baihongyu.com/