题解 | #【模板】链表#
【模板】链表
https://www.nowcoder.com/practice/97dc1ac2311046618fd19960041e3c6f
import sys
n=int(input())
linkList=[]
for i in range(n):
options=input().split(' ')
if options[0]=='insert':
try:
idx=linkList.index(options[1])
linkList.insert(idx,options[-1])
except:
linkList.append(options[-1])
elif options[0]=='delete':
try:
idx=linkList.index(options[1])
linkList.pop(idx)
except:
continue
if len(linkList)==0:
print('NULL')
else:
print(' '.join(linkList))


美团成长空间 2667人发布