LeetCode 83. 删除排序链表中的重复元素

题目链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/

给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。

示例 1:

输入: 1->1->2
输出: 1->2
示例 2:

输入: 1->1->2->3->3
输出: 1->2->3

 1 struct ListNode* deleteDuplicates(struct ListNode* head){
 2     if(head==NULL) return NULL;
 3     struct ListNode* p=head;
 4     struct ListNode* q=head->next;
 5     while(q!=NULL){
 6         if(q->val==p->val){
 7             p->next=q->next;
 8             free(q);
 9             q=p->next;
10         }
11         else{
12             p=q;
13             q=p->next;
14         }
15     }
16     return head;
17 }
原文地址:https://www.cnblogs.com/shixinzei/p/11341870.html