题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
const rl = require("readline").createInterface({ input: process.stdin }); rl.on('line',(line) => { const data = line.split(' ') const num = data.shift() const head = data.shift() const del = data.pop() let lianbiao = [] lianbiao[0] = head const index = data.findIndex(x => x === head) lianbiao[1] = data[index - 1] const arr = data.slice(2) for(let i = 0; i < arr.length; i++) { if((i + 1) % 2 === 0) { const index = lianbiao.findIndex(x => x === arr[i]) lianbiao.splice(index + 1,0,arr[i - 1]) } } console.log(lianbiao.filter(x => x !== del).join(' ')) })