题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
http://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
class Node: def __init__(self,value=0): self.value=value self.next=None class Linkedlist: def __init__(self,l): self.head=Node() first=Node(l[1]) self.head.next=first for j in range(2,len(l)-1,2): self.append(l[j],l[j+1]) self.pop(l[-1]) res=self.head.next while res: print(res.value,end=" ") res=res.next def append(self,value1,value2): cur=self.head.next node=Node(value1) while cur: if cur.value==value2: node.next=cur.next cur.next=node cur=cur.next def pop(self,value): cur=self.head while cur.next: if cur.next.value==value: cur.next=cur.next.next else: cur=cur.next while True: try: l=[int(i) for i in input().split()] Linkedlist(l) except: break