---
# System prepended metadata

title: 'Remove Duplicates from Sorted List <img src="https://img.shields.io/badge/-easy-brightgreen">'
tags: [data_structure_python]

---

---
tags: data_structure_python
---

# Remove Duplicates from Sorted List <img src="https://img.shields.io/badge/-easy-brightgreen">

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

<ins>**Example 1:**</ins>

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

<ins>**Example 2:**</ins>

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

# Solution

```python=
# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def deleteDuplicates(self, head: ListNode) -> ListNode:
        pointer1 = head
        if head is None or head.next is None:
            return head
        else:
            pointer2 = head.next
        
        
        while pointer2 is not None:
        
            if pointer1.val == pointer2.val:
                pointer2 = pointer2.next
                pointer1.next = pointer2
            else:
                pointer1 = pointer1.next
                pointer2 = pointer2.next
                
        return head
```