[Algorithm] 5 week(2.7 ~ 13) 3/3

Dev_min·2022년 2월 11일
0

algorithm

목록 보기
15/157

804. Unique Morse Code Words

var uniqueMorseRepresentations = function(words) {
    const morseCode = {
        a: ".-",
        b: "-...",
        c: "-.-.",
        d: "-..",
        e: ".",
        f: "..-.",
        g: "--.",
        h: "....",
        i: "..",
        j: ".---",
        k: "-.-",
        l: ".-..",
        m: "--",
        n: "-.",
        o: "---",
        p: ".--.",
        q: "--.-",
        r: ".-.",
        s: "...",
        t: "-",
        u: "..-",
        v: "...-",
        w: ".--",
        x: "-..-",
        y: "-.--",
        z: "--..",
    }
    const num = new Set()
    
    for (let word of words) {
        let str = '';
        for (let i = 0; i < word.length; i++) {
            str += morseCode[word[i]]
        }
        num.add(str)
    }
    return num.size
};
profile
TIL record

0개의 댓글