deno.land / x / masx200_leetcode_test@10.6.5 / sort-characters-by-frequency / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export default function frequencySort(s: string): string { const storage = new Map<string, number>(); for (const w of s) { storage.set(w, 1 + (storage.get(w) ?? 0)); } const sb: string[] = []; for ( const [c, frequency] of [...storage.entries()].sort((a, b) => { return +b[1] - a[1]; }) ) { for (let j = 0; j < frequency; j++) { sb.push(c); } } return sb.join("");}
masx200_leetcode_test

Version Info

Tagged at
a year ago