Python代码,时间复杂度O(N),空间复杂度O(1)
删除链表中重复的结点
http://www.nowcoder.com/questionTerminal/fc533c45b73a41b0b44ccba763f866ef
class Solution:
def deleteDuplication(self, pHead):
# write code here
if not pHead or not pHead.next:return pHead
head = ListNode(0)
head.next = pHead
pre = head
last = pre.next
while last:
if (last.next and last.val == last.next.val):
while last.next and last.val == last.next.val:
last = last.next
pre.next = last.next
last = pre.next
else:
pre = last
last = last.next
return head.next