1# Definition for singly-linked list.2# class ListNode:3# def __init__(self, val=0, next=None):4# self.val = val5# self.next = next6class Solution:7def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:8if not head:9return None1011result = tail = ListNode(-1)1213while head:14curr = head15head = head.next16hasDup = False17while (head) and (curr.val == head.val):18hasDup = True19headNext = head.next20head = None21head = headNext2223if hasDup == False:24tail.next = curr25tail = tail.next26tail.next = None2728return result.next