📅  最后修改于: 2022-03-11 15:03:19.508000             🧑  作者: Mango
/* Time complexity of solution: O(n) */
const getRepeatedChars = (str) => {
const chars = {};
for (const char of str) {
chars[char] = (chars[char] || 0) + 1;
}
return Object.entries(chars).filter(char => char[1] > 1).map(char => char[0]);
}
getRepeatedChars("aabbkdndiccoekdczufnrz"); // ["a", "b", "c", "d", "k", "n", "z"]