一、问题链接:
https://leetcode.com/problems/unique-morse-code-words/description/
三、编码:
class Solution {
public int uniqueMorseRepresentations(String[] words) {
String[] morse = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
Set<String> compare = new HashSet<>();
for(String temp:words){
String result = "";
char[] chars = temp.toCharArray();
for(char ch : chars){
result += morse[ch - 'a'];
}
compare.add(result);
}
return compare == null ? 0 : compare.size();
}
}