# Leetcode 83. Remove Duplicates from Sorted List
###### tags: `Leetcode`
題目
Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.
Example 1:
Input: head = [1,1,2]
Output: [1,2]
Example 2:
Input: head = [1,1,2,3,3]
Output: [1,2,3]
解法:
1.從203.稍微修改一下就可以了
2.記得preval要更新(如果當下那個不是重複的話)
======================
```
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* deleteDuplicates(struct ListNode* head){
if(head == NULL)
return NULL;
if(head->next == NULL)
return head;
int preval = head->val;
struct ListNode* pre = head;
struct ListNode* cur = head->next;
while(cur != NULL)
{
if(cur->val == preval)
pre->next = cur->next;
else
{
pre = cur;
preval = cur->val;
}
cur = cur->next;
}
return head;
}
```