class Solution:
def deleteDuplication(self, pHead):
# write code here
if not pHead:
return pHead
start=ListNode(0)
start.next=pHead
result=start
flag=0 #若当前节点与下一节点的值重复,则置1
while pHead.next:
while pHead.val==pHead.next.val:
flag=1
if not pHead.next.next:
start.next=None
return result.next
else:
pHead=pHead.next
if flag==0:
#如果当前节点与下一节点不重复,则将该节点添加进start所指的链表中
start.next=pHead
start=start.next
pHead=pHead.next
else:
#如果重复,则继续右移,进行判断
pHead=pHead.next
flag=0
#到达末尾处,将start指向最后一个不重复节点
start.next = pHead
return result.next