题解 | #【模板】链表#
【模板】链表
https://www.nowcoder.com/practice/97dc1ac2311046618fd19960041e3c6f
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
let n = parseInt(await readline());
let item = [];
while (n--) {
let line = await readline();
let args = line.split(" ");
switch (args[0]) {
case "insert":
if (!item.includes(args[1])) {
item.push(args[2]);
} else {
item.splice(item.indexOf(args[1]), 0, args[2]);
}
break;
case "delete":
if (item.includes(args[1])) {
item.splice(item.indexOf(args[1]), 1);
}
break;
}
}
if (item.length > 0) {
console.log(item.join(" "));
} else {
console.log("NULL");
}
})();
主要思路:数组模拟链表+javascript数组操作方法