题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
const readline = require("readline");
const rl = readline.createInterface({
input:process.stdin,
output:process.stdout
});
rl.on('line',function(data){
let map = new Map();
data.split("").forEach(item=>{
if(map.get(item)){
map.set(item,map.get(item)+1)
}else{
map.set(item,1)
}
});
const numArr = []
for(const [key,value] of map){
numArr.push(map.get(key))
}
const reg = [];
for(const [key,value] of map){
if(value == numArr.sort()[0]){
reg.push(key);
}
}
const str = `[${reg}]`
const regs = new RegExp(str, 'g')
console.log(data.replace(regs,''))
});
#考研调剂#
const rl = readline.createInterface({
input:process.stdin,
output:process.stdout
});
rl.on('line',function(data){
let map = new Map();
data.split("").forEach(item=>{
if(map.get(item)){
map.set(item,map.get(item)+1)
}else{
map.set(item,1)
}
});
const numArr = []
for(const [key,value] of map){
numArr.push(map.get(key))
}
const reg = [];
for(const [key,value] of map){
if(value == numArr.sort()[0]){
reg.push(key);
}
}
const str = `[${reg}]`
const regs = new RegExp(str, 'g')
console.log(data.replace(regs,''))
});
#考研调剂#