题解 | #从单向链表中删除指定值的节点#

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

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

char=input()
lists=char.split(" ")[1:]
start=lists[0]
end=lists[-1]
del lists[0]
del lists[-1]
new_lists=[]
for i in range(len(lists)):
    if i%2==0:
        if i==0:
            new_lists.append(lists[1])
            new_lists.append(lists[0])
        else:
            new_lists.insert(new_lists.index(lists[i+1])+1,lists[i])
    else:
        pass
new_lists.remove(end)
for i in new_lists:
    print(i,end=" ")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务