import java.util.*;
public class Solution {
    public ListNode deleteDuplicates (ListNode head) {
        if(head==null||head.next==null)
            return head;

        ListNode p = head;
        ListNode q = head.next;

        while(q!=null){
            if(p.val!=q.val){
                p = p.next;
                q = q.next;
            }else{
                while(q!=null && p.val==q.val)    q = q.next;

                p.next = q;
                p = p.next;
            }
        }
        return head;
    }
}