leetcode804
Posted 砥砺前行一笑中
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode804相关的知识,希望对你有一定的参考价值。
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)); } }
以上是关于leetcode804的主要内容,如果未能解决你的问题,请参考以下文章