美文网首页程序员
[Leetcode]804. Unique Morse Code

[Leetcode]804. Unique Morse Code

作者: 麻薯团子子 | 来源:发表于2018-08-19 23:45 被阅读8次

    一、问题链接:
    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();
        
    }
    

    }

    相关文章

      网友评论

        本文标题:[Leetcode]804. Unique Morse Code

        本文链接:https://www.haomeiwen.com/subject/mrbhiftx.html