题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
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 arr = []; while ((line = await readline())) { arr = line.split(""); } let setArr = [...new Set(arr)]; let lengthArr = []; setArr.forEach((item) => { let num = arr.filter((val) => val === item).length; lengthArr.push(num); }); const minNum = Math.min(...lengthArr); setArr.forEach((item, index) => { if (lengthArr[index] == minNum) { for (let i = 0; i < arr.length; i++) { if (item == arr[i]) { arr.splice(i, 1); i--; } } } }); console.log(arr.join("")); })();
#小白编程入门#