【leetcode】804

import java.util.*;
import java.lang.*;
public class Test{
    public static int fun_solve(String[] words){
        String[] trans_list = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
        StringBuilder sBuilder = new StringBuilder(); // 用于对word进行morse翻译的存储
        Set<String> words_morse_list = new HashSet<String>();//用于存放翻译好的所有word
        for(String word:words){
            char[] letter_list = word.toCharArray();
            for(char letter:letter_list){
                sBuilder.append(trans_list[letter - 'a']);
            }
            words_morse_list.add(sBuilder.toString());
            sBuilder.replace(0, sBuilder.length(), "");
        }
        return words_morse_list.size();
    }
    public static void main(String[] args){
        
        String[] words = {"gin", "zen", "gig", "msg"};
        System.out.println(fun_solve(words));
        
    }
  

}

  

猜你喜欢

转载自www.cnblogs.com/Sinkinghost/p/10720934.html
0条评论
添加一条新回复