19. 删除链表的倒数第 N 个结点

class Solution:def removeNthFromEnd(self, head: Optional[ListNode], n: int) -> Optional[ListNode]: right = head left = dummy = ListNode(next = head)for _ in range(n):right = right.nextwhile right:right = right.nextleft = left.nextleft.next = left.next.nextreturn dummy.next
二、83. 删除排序链表中的重复元素

class Solution:def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:if head is None:return headcur = headwhile cur.next:if cur.next.val == cur.val:cur.next = cur.next.nextelse:cur = cur.nextreturn head
三、82. 删除排序链表中的重复元素 II

class Solution:def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:dummy = ListNode(next=head)cur = dummywhile cur.next and cur.next.next: val = cur.next.valif cur.next.next.val == cur.next.val: while cur.next and cur.next.val == val: cur.next = cur.next.nextelse:cur = cur.nextreturn dummy.next