123456789101112131415161718192021 |
- from typing import Optional
- from utils import ListNode, list_to_linklist
- def deleteDuplicates(head: Optional[ListNode]) -> Optional[ListNode]:
- if not head:
- return head
- p = head
- while p.next:
- if p.val == p.next.val:
- p.next = p.next.next
- else:
- p = p.next
- return head
- print(deleteDuplicates(list_to_linklist([1, 1, 2])))
|