题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
while 1: try: INPUT = list(map(int, input().split())) n = INPUT[0] # 链表节点总个数 head_value = INPUT[1] # 头节点值 del_value = INPUT[len(INPUT) - 1] # 删除的值 link_rule = INPUT[2:len(INPUT) - 1] # 构建链表所需规则 link_value = [head_value] # 初始化链表 # 开始插值 for i in range(0, len(link_rule), 2): be_insert_value = link_rule[i + 1] insert_value = link_rule[i] link_value.insert(link_value.index(be_insert_value) + 1, insert_value) # 删除目标值 del link_value[link_value.index(del_value)] for i in range(len(link_value)): print(link_value[i], end=' ') except: break