题解 |

从单向链表中删除指定值的节点

http://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f

while True:
    try:
        nums = input().split(' ')
    except:
        break
    num_node = nums[0]
    head = nums[1]
    res = [head]
    nodes_back = nums[2:-1:2]
#     print('nodes_back:',nodes_back)
    nodes_fore = nums[3:-1:2]
#     print('nodes_fore:',nodes_fore)
    node_to_del = nums[-1]
    for node_back,node_fore in zip(nodes_back,nodes_fore):
        res.insert(res.index(node_fore)+1,node_back)
    res.remove(node_to_del)
    print(' '.join(res)+' ')
全部评论

相关推荐

2025-12-20 13:19
已编辑
曲阜师范大学 Java
点赞 评论 收藏
分享
2025-11-08 21:07
门头沟学院 Java
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务