1
# Definition for singly-linked list.
2
# class ListNode:
3
# def __init__(self, val=0, next=None):
4
# self.val = val
5
# self.next = next
6
class Solution:
7
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
8
if not head:
9
return None
10

11
result = tail = ListNode(-1)
12

13
while head:
14
curr = head
15
head = head.next
16
hasDup = False
17
while (head) and (curr.val == head.val):
18
hasDup = True
19
headNext = head.next
20
head = None
21
head = headNext
22

23
if hasDup == False:
24
tail.next = curr
25
tail = tail.next
26
tail.next = None
27

28
return result.next

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0