题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
import sys
l = input().split(' ')
#print(l)
h = l[1] #头节点
d = l[-1] #删除节点
ans = [h] #结果列表,直接把头节点放入
#print(l[2:-1]) # 插入的格式
l1 = l[2:-1][::2] #插入的数字 [::2] 从第0位,步长2 取值
l2 = l[2:-1][1::2] #插入的位置(在后面插入) [1::2] 从第1位,步长2 取值
for i in range(len(l2)):
#列表.insert(位置,值)
ans.insert(ans.index(l2[i])+1, l1[i]) # list.index(s) 取第一次出现s字符的index
ans.remove(d) # list.remove(x) 直接删除值x
print(' '.join(ans))

三奇智元机器人科技有限公司公司福利 100人发布