题目: 

13.LeetCode 804. Unique Morse Code Words

 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();
    }
}

 

相关文章:

  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-07-10
  • 2022-12-23
  • 2022-02-19
  • 2021-06-07
猜你喜欢
  • 2022-03-01
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
相关资源
相似解决方案