13.LeetCode 804. Unique Morse Code Words
题目:
class Solution {
public int uniqueMorseRepresentations(String[] words) {
String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
TreeSet<String> set = new TreeSet<String>();//基于平衡二叉树实现
for(String word : words){
StringBuilder ret = new StringBuilder();
for(int i= 0;i<word.length();i++){
ret.append(codes[word.charAt(i)-'a']);
}
set.add(ret.toString());
}
return set.size();
}
}