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

  

【leetcode】804的更多相关文章

  1. 【LeetCode】804. Unique Morse Code Words 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 set + map set + 字典 日期 题目地 ...

  2. 【Leetcode】804. Unique Morse Code Words

    Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...

  3. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  4. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  5. 53. Maximum Subarray【leetcode】

    53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...

  6. 27. Remove Element【leetcode】

    27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...

  7. 【刷题】【LeetCode】007-整数反转-easy

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...

  8. 【刷题】【LeetCode】000-十大经典排序算法

    [刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法

  9. 【leetcode】893. Groups of Special-Equivalent Strings

    Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...

随机推荐

  1. RHEL5.X 重启网卡出现./network-functions: line 78: .: ifcfg-eth0: file not found

    错误信息: 红帽RHEL5.5系统,重启网卡报错 [root@localhost network-scripts]# service network restart Shutting down int ...

  2. 微服务架构之spring cloud eureka

    Spring Cloud Eureka是spring cloud的核心组件,负责服务治理功能,起到中心枢纽作用,其它组件都依赖eureka来获取服务,然后再根据项目需求实现自己的业务,eureka在整 ...

  3. Android解析WindowManagerService(二)WMS的重要成员和Window的添加过程

    前言 在本系列的上一篇文章中,我们学习了WMS的诞生,WMS被创建后,它的重要的成员有哪些?Window添加过程的WMS部分做了什么呢?这篇文章会给你解答. 1.WMS的重要成员 所谓WMS的重要成员 ...

  4. 网络测速 php代码

    <?php /*=====http://hi.csdn.net/yinyiniao=====*/ $fp=fopen("cs.txt","w"); for ...

  5. php自动获取上一个月的起始时间

    1.借鉴评论的方法[20170309 edit] function get_month_start_end($timestamp) { !empty($timestamp) OR $timestamp ...

  6. js实现查找字符串出现最多的字符和次数

    代码如下: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=" ...

  7. OC继承

    1.成员访问类型 private:私有成员,不能被外部函数访问(使用),也不能被子类继承: protected:保护成员,不能被外部函数访问,可以被子类继承: public:公有成员,可以被外部函数访 ...

  8. Dictionary<Tkey.TValue>与SortedList

    一.概述 表示Key/Value集合,可以添加删除元素,允许按Key来访问元素.是Hashtable的泛型等效类. 它需要一个相等实现来确定键是否相等,可以使用实现了IEqualityComparer ...

  9. 安装LAMP PHP的./configure 參数,未出现MYSQ

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/default7/article/details/30613781 编译參数: ./configure ...

  10. 「CF1025D Recovering BST」

    题目 郑州讲过的题了 发现这是一个二叉搜索树,给出的还是中序遍历,我们很自然的想到我们需要可以用一个\(f[i][j][k](k\in[i,j])\)来表示区间\([i,j]\)能不能形成以\(k\) ...