删除链表中重复结点,使每个结点最多出现2次
class Solution(object):
def removeDuplicates(self, head):
"""
:type head: ListNode
"""
if not head or not head.next:
return head
low = head
fast = head.next
while fast:
if fast.next and fast.val == low.val and fast.val == fast.next.val:
fast.next = fast.next.next
else:
low = fast
fast = fast.next
return head