Skip to content

Commit

Permalink
Time: 54 ms (64.08%) | Memory: 51.2 MB (14.27%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Mar 11, 2024
1 parent 37ad6ee commit 1062760
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 807-custom-sort-string/custom-sort-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @param {string} order
* @param {string} s
* @return {string}
*/
var customSortString = function(order, s) {
const charCount = {};
for (const char of order) {
charCount[char] = 0;
}

for (const char of s) {
if (charCount[char] !== undefined) {
charCount[char]++;
}
}

let sortedS = '';
for (const char of order) {
sortedS += char.repeat(charCount[char]);
}

for (const char of s) {
if (!order.includes(char)) {
sortedS += char;
}
}

return sortedS;
};

0 comments on commit 1062760

Please sign in to comment.