출처 : https://leetcode.com/problems/unique-morse-code-words/
class Solution {
public int uniqueMorseRepresentations(String[] words) {
Map<Character, String> map = new HashMap<>();
String[] given = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.",
"---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
char a = 'a';
int ind = 0;
while (a <= 'z') {
map.put(a, given[ind++]);
a++;
}
Set<String> set = new HashSet<>(); //duplicates not allowed
for (int i = 0; i < words.length; i++) {
String concat = "";
for (int j = 0; j < words[i].length(); j++) {
if (map.containsKey(words[i].charAt(j))) {
concat += map.get(words[i].charAt(j));
}
}
set.add(concat);
}
return set.size();
}
}