import java.util.*;

/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
     // 重复元素只保留一次!
    public ListNode deleteDuplicates (ListNode head) {
        // write code here
        if(head == null) return head;
        ListNode fake_head = new ListNode(-1);
        fake_head.next = head;
        ListNode pre = fake_head,cur = head;
        
        while(cur != null){
            while(cur != null && cur.next != null && cur.val == cur.next.val){
                cur = cur.next;
            }
            pre.next = cur;
            pre = pre.next;
            cur = cur.next;
        }
        return fake_head.next;
    }
}