LC 0082 [M] Remove Duplicates from Sorted List II - ALawliet/algorithms GitHub Wiki
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def deleteDuplicates(self, head):
dum = pre = ListNode(0)
dum.next = head
cur = head
while cur and cur.next:
if cur.val == cur.next.val:
while cur and cur.next and cur.val == cur.next.val:
cur = cur.next
cur = cur.next
pre.next = cur
else:
pre = pre.next
cur = cur.next
return dum.next