题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
http://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
不知道有没有隐含bug。。。是可以通过的
def findIndex(c): index=0 for num in link: if num==c: return index else : index+=1 while True: try : s=input().split() mount=s[0] head=s[1] delit=s[-1] s=s[2:-1] p=[] #print(s) link=[] for i in range(0,len(s),2): p.append((s[i],s[i+1])) link.append(p[0][1]) for item in p: idx=findIndex(item[1]) link.insert(idx+1,item[0]) rg=len(link) for i in range(rg): if link[i]==delit: link.pop(i) break #link=list(map(int, link)) print(" ".join(link)) # print(link) except: break