题解 | #字符统计#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
let line;
function func(line) {
let rtnVal;
const arr = line.split('');
const obj = {}; // 哈希map,本质是一个obj
const res = [...new Set(arr)]; // 去重
// map结构保存k-v
res.forEach(item => {
const count = arr.filter(el => el == item).length;
obj[item] = count;
})
// 数组按照count大小排序
res.sort((a,b) => {
if(obj[a] == obj[b]) {
return a.charCodeAt(0) - b.charCodeAt(0);
} else {
return obj[b] - obj[a];
}
})
rtnVal = res.join('');
return rtnVal;
}
while (line = readline()) {
print(func(line));
}