题解 | #删除链表中重复的结点#
删除链表中重复的结点
http://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef
# def __init__(self, x):
# self.val = x
# self.next = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param pHead ListNode类
# @return ListNode类
#
class Solution:
def deleteDuplication(self , pHead: ListNode) -> ListNode:
# write code here
ppre = ListNode(-1)
pre = ListNode(-1)
ppre.next = pre
pre.next = pHead
while pHead and pHead.next:
if pHead.val != pHead.next.val and pHead.next:
pre.next = pHead
print(pre.next.val )
pre = pre.next
pHead = pHead.next
else:
val = pHead.val
while pHead and pHead.val == val:
pHead = pHead.next
pre.next = pHead # 如果不加这一句则删除完还是if语句里的连接情况,即pHead的连接情况
return ppre.next.next