Algorithm

LeetCode 804 : Unique Morse Code Words

쿠케캬캬 2022. 8. 17. 22:35
반응형

https://leetcode.com/problems/unique-morse-code-words/

 

Unique Morse Code Words - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

변환된 단어를 set에 저장하여 중복을 제거해주었습니다.

 

class Solution {
public:
    string morse[26] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
    
    set<string> transWords;
    int uniqueMorseRepresentations(vector<string>& words) {
        for(string& word : words) {
            string temp = "";
            for(char w : word) temp += morse[w - 'a'];
            transWords.insert(temp);
        }
        return transWords.size();
    }
};
반응형