剑指offer python版 删除链表中重复的结点
Posted findtruth123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了剑指offer python版 删除链表中重复的结点相关的知识,希望对你有一定的参考价值。
class ListNode(object): def __init__(self,x): self.val=x self.next=None class Link(object): def __init__(self,values=None): self.nodes=self.set_link(values) if values else None def get_link(self): return self.nodes def set_link(self,values): if not values : return False head=ListNode(0) move=head try: for i in values: tmp=ListNode(i) move.next=tmp move=move.next except Exception as e: print(e) return head.next def deleteDuplication(self, pHead): first = ListNode(-1) first.next = pHead last = first while pHead and pHead.next: if pHead.val == pHead.next.val: val = pHead.val while pHead and val==pHead.val: pHead = pHead.next last.next = pHead else: last = pHead pHead = pHead.next return first.next
以上是关于剑指offer python版 删除链表中重复的结点的主要内容,如果未能解决你的问题,请参考以下文章