题解 | 从单向链表中删除指定值的节点
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
#忘记了链表的定义格式,直接用列表写了。最后输出时使用了小聪明,成功解决问题。现在要去看链表的解答方法了 def search(y, lst): for i, x in enumerate(lst): if y == x: return i return -1 nums = list(map(int, input().split())) list1 = [] list1.append(nums[1]) for i in range(2, len(nums)-1, 2): x = nums[i] y = nums[i + 1] j = search(y, list1) if j == -1: list1.append(x) else: list1.insert(j + 1, x) string1 = [] for x in list1: if x != nums[-1]: string1.append(str(x)) print(' '.join(string1))