**[82. Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/)**
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
**Example 1:**
```
Input: 1->2->3->3->4->4->5
Output: 1->2->5
```
**Example 2:**
```
Input: 1->1->1->2->3
Output: 2->3
```

**Solution:**
Runtime: 1 ms<br/>
Memory Usage: 	36.3 MB
```java
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if(head == null || head.next == null)
            return head;
        ListNode dummy = new ListNode(Integer.MIN_VALUE - 1);
        dummy.next = head;
        ListNode p1 = dummy, p2 = head, p = dummy; 
        while(p2 != null) {
            if(p1.val == p2.val) {                
                p2 = p2.next;
                p.next = null;
            } else if(p1.val != p2.val) {
                if(p2.next == null || (p2.next != null && p2.val != p2.next.val)) {
                    p.next = p2;
                    p = p.next;
                }
                p1 = p2;
                p2 = p2.next;
            }
        }
        return dummy.next;
    }
}
```