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

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

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

import sys
while True:
    try:
        ss = input().strip().split()
        n = int(ss[0])
        L = []
        L.append(ss[1])
        c_list = ss[2:-1]
        #按规则构造列表
        for i in range(n-1):
            v = c_list[2*i]
            f = c_list[2*i + 1]
#             print(v,f)
            index = L.index(f)
#             print(index)
            L.insert(index + 1, v)
#         print(L)
        L.remove(ss[-1])
#         if len(L) == 0:
#             print("0")
#         else:
        print(" ".join(L))
    except:
#         print(sys.exc_info())
        break

















全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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