-
804. Unique Morse Code Words릿코드(LEETCODE) 2020. 3. 5. 07:35반응형
https://leetcode.com/problems/unique-morse-code-words
class Solution {
public:
int uniqueMorseRepresentations(vector& words) {
vector morse = {".-","-...","-.-.","-..",".","..-.","--.",
"....","..",".---","-.-",".-..","--","-.",
"---",".--.","--.-",".-.","...","-","..-",
"...-",".--","-..-","-.--","--.."};
map<string, int> m;
for(int i=0; i<words.size(); i++) {
string s = words[i];
string cand;
for(auto a:s){
cand += morse[a - 'a'];
}
m[cand]++;
}
return m.size();
}
};반응형'릿코드(LEETCODE)' 카테고리의 다른 글
53. Maximum Subarray (0) 2020.04.09 202. Happy Number (0) 2020.04.09 1252. Cells with Odd Values in a Matrix (0) 2020.03.03 1207. Unique Number of Occurrences (0) 2020.03.03 1365. How Many Numbers Are Smaller Than the Current Number (0) 2020.03.03