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

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

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
全部评论
大佬, ind = new.index(num[i+1]) new.insert(ind+1,num[i]) 类似这种找规律,如何入门呢?
点赞
送花
回复
分享
发布于 2022-01-08 15:51
光理解题意花了我2小时多
点赞
送花
回复
分享
发布于 2022-11-01 21:07 陕西
秋招专场
校招火热招聘中
官网直投
这种到底可不可行?毕竟不是链表结构
点赞
送花
回复
分享
发布于 2023-02-26 20:47 江苏

相关推荐

点赞 评论 收藏
转发
11 3 评论
分享
牛客网
牛客企业服务