class Solution{
public ListNode deleteDuolicates(ListNode head){
ListNode dummy = new ListNode();
ListNode tail = dummy;
while (head != null){
if(head.next ==null || head.val !=head.next.val){
tail.next = head;
tail = head;
}
while (head.next !=null && head.val == head.next.val)head = head.next;
head = head.next;
}
tail.next = null;
return dummy.next;
}
}