题解 | #字符统计#
字符统计
http://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
var line=readline() let arr = line.split(''); //6uym66c0l609vb6mg75q90zyf9d4styi257709 let obj = {}; let res = [...new Set(arr)];//[6,u,y,m,c,0,l,9,v,b,g,7,5,q,z,f,d,4,s,t,i,2] //console.log(res) for(let i=0;i<res.length;i++){ var count=1 for(let j=0;j<arr.length;j++){ if(res[i]===arr[j]){ obj[res[i]]=count++ } } } res.sort((a,b)=>{ if(obj[a]===obj[b]){ return a.charCodeAt(0)-b.charCodeAt(0)//升序 }else{ return obj[b]-obj[a]//降序 } }) console.log(res.join(''))