Skip to content

Commit ce894e8

Browse files
authoredSep 29, 2024
Fixed Formatting 0767-reorganize-string.js
1 parent a8b67d4 commit ce894e8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed
 

‎javascript/0767-reorganize-string.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@
88
var reorganizeString = function(s) {
99

1010
const maxQ = new MaxPriorityQueue({
11-
compare: (a,b) => {
11+
compare: (a, b) => {
1212
return b[0] - a[0];
1313
}
1414
});
1515

1616
const freq = {};
17-
for(let i = 0; i < s.length; i++) {
17+
for (let i = 0; i < s.length; i++) {
1818
const char = s[i];
1919
freq[char] = (freq[char] && freq[char] + 1 || 1);
2020
}
21-
for(const key in freq) {
21+
for (const key in freq) {
2222
const val = freq[key];
2323
maxQ.enqueue([val, key]);
2424
}
2525

2626
let orgStr = "";
27-
while(!maxQ.isEmpty()) {
27+
while (!maxQ.isEmpty()) {
2828

2929
const [occurance, char] = maxQ.dequeue();
3030

31-
if(orgStr[orgStr.length - 1] === char) {
31+
if (orgStr[orgStr.length - 1] === char) {
3232

33-
if(maxQ.isEmpty()) return "";
33+
if (maxQ.isEmpty()) return "";
3434

3535
const [occurance1, char1] = maxQ.dequeue();
3636
orgStr += char1;
37-
if(occurance1-1) {
38-
maxQ.enqueue([occurance1-1, char1]);
37+
if (occurance1 - 1) {
38+
maxQ.enqueue([occurance1 - 1, char1]);
3939
}
4040
maxQ.enqueue([occurance, char]);
4141
} else {
4242
orgStr += char;
43-
if(occurance-1) {
44-
maxQ.enqueue([occurance-1, char]);
43+
if (occurance - 1) {
44+
maxQ.enqueue([occurance - 1, char]);
4545
}
4646
}
4747
}

0 commit comments

Comments
 (0)
Please sign in to comment.