# 083J?. Remove Duplicates from Sorted List

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

## Method 1: Iteration

这个题的思想和 [026](https://zichao-yang.gitbook.io/leetcode-zichao/leetcode-p001-100/leetcode-026-remove-duplicates-from-sorted-array)一样。

### Java Solution:

```java
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null ){
            return null;
        }
        ListNode dummyhead = new ListNode(0);
        dummyhead.next = head;
        ListNode p = head;
        while( p != null) {
            if(p.val != head.val){
                head = head.next;
                head.val = p.val;
            }
            p = p.next;
        }
        head.next = null;
        return dummyhead.next;

    }
}
```
