题解 | #删除有序链表中重复的元素-II#
删除有序链表中重复的元素-II
http://www.nowcoder.com/practice/71cef9f8b5564579bf7ed93fbe0b2024
class Solution:
def deleteDuplicates(self , head: ListNode) -> ListNode:
# write code here
if not head:
return head
dummy = ListNode(-1)
dummy.next = head
ans = dummy
while ans.next and ans.next.next:
if ans.next.val == ans.next.next.val:
tmp = ans.next.val
ans.next = ans.next.next.next
while ans.next and ans.next.val == tmp:
ans.next = ans.next.next
else:
ans = ans.next
return dummy.next