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

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

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

while True:
    try:
        num = list(map(int,input().split()))
        n = len(num)
        new = []
        for i in range(2,n-1,2): 
            if num[i+1] not in new: #没有就追加
                new.append(num[i+1])
                new.append(num[i])
            else: #有就插队
                ind = new.index(num[i+1])
                new.insert(ind+1,num[i])
        #循环删除节点
        try:
            while True:
                new.remove(num[-1])
        except:
            pass
        #输出
        new = [str(x) for x in new]
        print(' '.join(new))
    except:
        break
全部评论
这种到底可不可行?毕竟不是链表结构
点赞 回复 分享
发布于 2023-02-26 20:47 江苏
光理解题意花了我2小时多
点赞 回复 分享
发布于 2022-11-01 21:07 陕西
大佬, ind = new.index(num[i+1]) new.insert(ind+1,num[i]) 类似这种找规律,如何入门呢?
点赞 回复 分享
发布于 2022-01-08 15:51

相关推荐

大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
评论
11
3
分享

创作者周榜

更多
牛客网
牛客企业服务