LeetCode804. 唯一摩尔斯密码词

Posted 不学无墅_NKer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode804. 唯一摩尔斯密码词相关的知识,希望对你有一定的参考价值。

 

 

 

import java.util.TreeSet;
class Solution {
    public int uniqueMorseRepresentations(String[] words) {
        String[] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};

        TreeSet<String> set = new TreeSet<>();
        for(String word: words){
            StringBuilder res = new StringBuilder();
            for(int i = 0; i < word.length(); i++){
                res.append(codes[word.charAt(i) - \'a\']);               
            }
            set.add(res.toString());
        }
        return set.size();
    }
}
Solution 1

 

以上是关于LeetCode804. 唯一摩尔斯密码词的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 804 唯一摩尔斯密码词

LeetCode 804 唯一摩尔斯密码词[map] HERODING的LeetCode之路

[804].唯一摩尔斯密码词

[804].唯一摩尔斯密码词

《LeetCode刷题》804. 唯一摩尔斯密码词(java篇)

804-唯一摩尔斯密码词