classSolution: defdeleteDuplicates(self, head: ListNode) -> ListNode: q = ListNode() q.next = head ans = q while q and q.nextand q.next.next: while q.nextand q.next.nextand q.next.val == q.next.next.val: val = q.next.val p = q.next while p and p.val == val: p = p.next q.next = p q = q.next return ans.next