题解 | #找出字符串中第一个只出现一次的字符#
找出字符串中第一个只出现一次的字符
https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const inputs= [] rl.on("line", function (line) { if (line != "") { inputs.push(line) const tokens = inputs[0].split(""); let isSig = []; let arr = [...new Set(tokens)]; for (let i = 0; i < arr.length; i++) { let index = tokens.indexOf(arr[i]); tokens.splice(index, 1); if (tokens.indexOf(arr[i]) == -1) { isSig.push(arr[i]); break; } } if (isSig.length) { console.log(isSig[0]); } else { console.log(-1); } } });真是服了牛客这输入输出,多了半天没搞好,原来输入完又加了个换行跟在后面