题解 | #删除链表中重复的结点#
删除链表中重复的结点
http://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef
# -*- coding:utf-8 -*-时间复杂度为O(n)的解法,只需一次遍历
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def deleteDuplication(self, pHead):
# write code here
a=ListNode(None)
a.next=pHead
r=a
while(r.next and r.next.next):
if r.next.val==r.next.next.val:
d=r.next.val
s=r.next.next
while(s and s.val==d):
s=s.next
r.next=s
else:
r=r.next
return(a.next)