题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
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 const str = await readline(); const map = new Map(); let res = "" for (let i = 0; i < str.length; i++) { map.set(str[i], (map.get(str[i]) || 0) + 1); } const sortedEntries = [...map.entries()].sort((a, b) => { if (a[1] === b[1]) { // 如果值相同 return a[0].localeCompare(b[0]); // 按照 ASCII 码排序 } else { return b[1] - a[1]; // 否则按照值的大小降序排序 } }); sortedEntries.forEach((item) => { res += item[0] }) console.log(res) })();