We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
删除字符串中出现次数最少的字符
描述 实现删除字符串中出现次数最少的字符,若出现次数最少的字符有多个,则把出现次数最少的字符都删除。输出删除这些单词后的字符串,字符串中其它字符保持原来的顺序。 数据范围:输入的字符串长度满足 1≤n≤20 ,保证输入的字符串中仅出现小写字母 输入描述: 字符串只包含小写英文字母, 不考虑非法输入,输入的字符串长度小于等于20个字节。 输出描述: 删除字符串中出现次数最少的字符后的字符串。 示例1 输入: aabcddd 复制 输出: aaddd
The text was updated successfully, but these errors were encountered:
let line = readline(); const map = {}; let min = 20; for(let j=0;j<line.length;j++){ map[line[j]]=(map[line[j]] || 0)+1; } Object.keys(map).forEach(item=>{ min = Math.min(min,map[item]); }); for(let i = 0;i<line.length;i++){ if(map[line[i]] === min){ line = line.replace(line[i],''); i--; } } console.log(line)
Sorry, something went wrong.
No branches or pull requests
删除字符串中出现次数最少的字符
The text was updated successfully, but these errors were encountered: