```
class Solution:
# @param head, a ListNode
# @return a ListNode
def deleteDuplicates(self, head):
fh = ListNode(-1)
prev = fh
p = head
while p:
q = p.next
while q and q.val == p.val:
q = q.next
# q either is None or q.val != p.val
if q == p.next:
# p is distinct
prev.next = p
p = p.next
prev = prev.next
prev.next = None
else:
p = q
return fh.next
```