# 83. Remove Duplicates from Sorted List

**<font color=red>难度: Easy</font>**

## 刷题内容

> 原题连接

* https://leetcode.com/problems/remove-duplicates-from-sorted-list/description/

> 内容描述

```
Given a sorted linked list, delete all duplicates such that each element appear only once.

Example 1:

Input: 1->1->2
Output: 1->2
Example 2:

Input: 1->1->2->3->3
Output: 1->2->3
```

## 解题方案

> 思路 1
******- 时间复杂度: O(N)******- 空间复杂度: O(1)******

先写了一个复杂一点的版本，beats 76.63%

```python
class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        if not head:
            return head
        dummy = prev = ListNode(None)
        while head:
            if head.val == prev.val:
                if not head.next:
                    prev.next = None
            else:
                prev.next = head
                prev = prev.next
            head = head.next
            
        return dummy.next
```
更简单的dummy 大法，beats 100%

```python
class Solution(object):
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        dummy = head
        while head:
            while head.next and head.next.val == head.val:
                head.next = head.next.next    # skip duplicated node
            head = head.next     # not duplicate of current node, move to next node
        return dummy  
```
