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

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

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(' '))
});



全部评论

相关推荐

在笔试的大西瓜很矫健:这跟数分八竿子打不着,先去了解实习要会什么再说找实习吧
点赞 评论 收藏
分享
双尔:反手回一个很抱歉,经过慎重考虑,您与我的预期暂不匹配,感谢您的投递
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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