题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
let str; while(str = readline()){ let strArr = str.split('') getMin(str,strArr) } function getMin(str,strArr){ let obj = {}; for(let v of strArr){ if(obj[v]){ obj[v]++; }else{ obj[v] = 1; } } //算出出现最少次数的数值是多少 let minNum = 20; //因为最多也就只能出现20次 for(let key in obj){ if(obj[key] < minNum){ minNum = obj[key]; } } let res = strArr; for(let key in obj){ if(obj[key] == minNum){ res = res.filter((v)=>{ return v!=key; }) } } console.log(res.join('')) }