# 82. Remove Duplicates from Sorted List II

### Description

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only *distinct* numbers from the original list.

Return the linked list sorted as well.

### Constraints

### Approach

### Links

* GeeksforGeeks
* [Leetcode](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/)
* [ProgramCreek](https://www.programcreek.com/2014/06/leetcode-remove-duplicates-from-sorted-list-ii-java/)
* YouTube

### **Examples**

{% tabs %}
{% tab title="Example 1" %}
**Input:** 1 -> 2 -> 3 -> 3 -> 4 -> 4 -> 5

**Output:** 1 -> 2 -> 5
{% endtab %}

{% tab title="Example 2" %}
**Input:** 1 -> 1 -> 1 -> 2 -> 3

**Output:** 2 -> 3
{% endtab %}
{% endtabs %}

### **Solutions**

{% tabs %}
{% tab title="Solution 1" %}

```java
/**
 * Time complexity : 
 * Space complexity : 
 */

/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null) return null;
        ListNode node = new ListNode(-1);
        node.next = head;

        ListNode curr = node;
        while(curr.next != null && curr.next.next != null) {
            if(curr.next.val == curr.next.next.val) {
                int value = curr.next.val;
                while(curr.next != null && curr.next.val == value) {
                    curr.next = curr.next.next;
                }
            } else {
                curr = curr.next;
            }
        }
        
        return node.next;
    }
}
```

{% endtab %}
{% endtabs %}

### **Follow up**

*
