题解 | #从单向链表中删除指定值的节点#
从单向链表中删除指定值的节点
https://www.nowcoder.com/practice/f96cd47e812842269058d483a11ced4f
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on("line", function (line) {
const tokens = line.split(" ");
tokens.shift() // 第一个不要
const delChar = tokens.pop();
const head = tokens.shift();
let left = 0;
let right = 1;
const linkList = [head]
while(right < tokens.length){
const cur = tokens[left];
const target = tokens[right];
const index = linkList.indexOf(target);
linkList.splice(index+1,0,cur)
left +=2;
right +=2;
}
console.log(linkList.filter(i=>i!=delChar).join(' '))
});
安克创新 Anker公司福利 581人发布