题目:1-1-2-3-3-3-4-5-6-6-7,删除重复节点后返回2-4-5-7
def delete_duplicate(head):
h = Node(0)
k = h
p = head
if not p or not p.next:
return head
q = p.next
if p.val!=q.val:
k.next = p
k = k.next
while q.next:
if q.val!=p.val and q.val!=q.next.val:
k.next = q
k = k.next
p = q
q = q.next
if p.val!=q.val:
k.next = q
k = k.next
k.next = None
return h.next
注:不重复节点判断标准为,和前、后节点都不相同,注意头节点和尾结点要单独判断。