class Solution {
    public int uniqueMorseRepresentations(String[] words) {
        String[] dotAndDash = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        Set<String> set = new HashSet<String>();
        for (String word: words) {
            StringBuilder concatenation = new StringBuilder();
            for (char c: word.toCharArray()) {
                concatenation.append(dotAndDash[c-97]);
            }
            set.add(concatenation.toString());
        }
        int result = set.size();
        System.out.println(result);
        return result;
    }
}

 

相关文章:

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