File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,29 @@ var frequencySort = function(s) {
2222 . map ( entry => entry [ 0 ] . repeat ( entry [ 1 ] ) )
2323 . join ( '' ) ;
2424} ;
25+
26+ // Doesno work with big string Why?
27+ // var frequencySort = function(s) {
28+ // const freqMap = new Map();
29+
30+ // // Подсчёт частоты символов
31+ // for (const ch of s) {
32+ // freqMap.set(ch, (freqMap.get(ch) || 0) + 1);
33+ // }
34+
35+ // const maxHeap = new MaxHeapAdhoc();
36+
37+ // // Заполняем макс-хипу (отрицательное значение для симуляции макс-хипы)
38+ // for (const [ch, freq] of freqMap.entries()) {
39+ // maxHeap.add([-freq, ch.repeat(freq)]);
40+ // }
41+
42+ // let result = "";
43+
44+ // // Извлекаем символы в порядке убывания частоты
45+ // while (maxHeap.heap.length) {
46+ // result += maxHeap.poll()[1];
47+ // }
48+
49+ // return result;
50+ // };
Original file line number Diff line number Diff line change @@ -9,7 +9,14 @@ var frequencySort = function(s) {
99const example1 = frequencySort ( "tree" ) ; // "eert"
1010const example2 = frequencySort ( "cccaaa" ) ; // "aaaccc"
1111const example3 = frequencySort ( "Aabb" ) ; // "bbAa"
12+ const example4 = frequencySort ( "BbAaCc" ) ; // "ccbaCBA"
13+ const example5 = frequencySort ( "BbAAAaaCc" ) ; // "AAAaacbCB"
14+ const example6 = frequencySort ( "BabBbBbBbbABBABBbAabbbABBaBbBabaabBbbBAAaaAbbAABaAbBBaAaaaaBABbaBbAAbBBbbABBaaBBbabAbBBAAbAbaaaBrBBaAaabAbbBbABabABaBabBBBBBaAbAaABaaaAAaAgAaAaBAbaBaBaBbbbBbABBBBaaaBbbbAbbbBaBBaAbBBbbaaaaaBbbaaAAbAABBABBaAAABBbbBbBbbBbaABBAAbBAbabbbabwBbbBArABaBBbabBaBabABABaabBBABBAabBAAaabbbbBAababAaBaaAaBbBbBAAbaBabBbabaBaaBbaabABAbbBbaBAbabABbbaAaBbAAAbBbaabBBAbbbABbaabAAAaaaBaBaaaBBABbBAbAAbaABaabbbbBBAabbbBABBbaABBAAAabaAbaBAbbaBaBbAbaAAbBaBAbAabBBbBsBabbbAaBbabAAaABAaBAAAbbaBaAbABABBBAbABABbbbBaaBaBAbABAbaaAbBbAABBbAbbAaBbabaBbABAAbAABbbAabAaAaBbBBbAAbBbaaaBAbABBbBBaCabBBabBAaBbBaAbbBAbbBaBAabBAababAaAbaAaabBBBABabaabBAAAabBAAAbBAbAaaaAbAaBaAbbAaABABBbBBAABAabaAAbBaBbAAaabbABBBABaBAabAbAAbBbAabAbaBbAbBAABAABAAAbBaaaaBabbaBABBaABbAabBaBAbAbbABAbaAAbaAAaBaabaBbBBbBABAABBABBaabBBbBBABAAaAAbbBbABBBbAabAbABbAAAbbAbABbbAbBAbabbbBBBBbAAabaabBABABaaAbaBBBBbbABbBbBABBaAbAaBBABBBabAABBBBBbBBabBaaBbaaBaBbaBbbAABbbAaaBBBbabaabBABABBBGabbBAbaBabAaAAabbbBaabBBbABBabBabbBbAbbAaBbAaAabBabBBbaBLaAbbAaaBaabAAab" ) ; // "AAAaacbCB"
1215
1316console . log ( example1 ) ;
1417console . log ( example2 ) ;
1518console . log ( example3 ) ;
19+ console . log ( example4 ) ;
20+ console . log ( example5 ) ;
21+ console . log ( example6 ) ;
22+
You can’t perform that action at this time.
0 commit comments