
class Solution {
private static String[] map = {
".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--.."
};
public int uniqueMorseRepresentations(String[] words) {
if(words==null)
return 0;
HashSet<String> set = new HashSet<String>();
for(String s:words){
StringBuilder sb=new StringBuilder();
for(char c:s.toCharArray()){
sb.append(map[c-'a']);
}
set.add(sb.toString());
}
return set.size();
}
}