📌  相关文章
📜  如何在javascript代码示例中查找字符串中的重复字符

📅  最后修改于: 2022-03-11 15:03:19.508000             🧑  作者: Mango

代码示例1
/* 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"]