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

}

  

上一篇:display :inline-block 处理点小障碍


下一篇:17. Letter Combinations of a Phone Number