【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)); } }
【leetcode】804的更多相关文章
- 【LeetCode】804. Unique Morse Code Words 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 set + map set + 字典 日期 题目地 ...
- 【Leetcode】804. Unique Morse Code Words
Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【Leetcode】Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...
- 53. Maximum Subarray【leetcode】
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one ...
- 27. Remove Element【leetcode】
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place ...
- 【刷题】【LeetCode】007-整数反转-easy
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位 ...
- 【刷题】【LeetCode】000-十大经典排序算法
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法
- 【leetcode】893. Groups of Special-Equivalent Strings
Algorithm [leetcode]893. Groups of Special-Equivalent Strings https://leetcode.com/problems/groups-o ...
随机推荐
- _tcsrchr
原文:http://www.cnblogs.com/diyunpeng/archive/2012/01/18/2325289.html _tcsrchr #include <afx.h> ...
- Python爬虫教程-06-爬虫实现百度翻译(requests)
使用python爬虫实现百度翻译(requests) python爬虫 上一篇介绍了怎么使用浏览器的[开发者工具]获取请求的[地址.状态.参数]以及使用python爬虫实现百度翻译功能[urllib] ...
- 本地调试接口返回信息不对 以及 jar冲突问题
今天下午在本地调试的时候碰到个很奇怪的问题:服务调用接口,返回的明明是有数据的,然后通过gson转换对象后,对象里面并没有自己想要的数据.看了代码什么的都没有问题.思考到底是哪里出了问题,想了半天想到 ...
- matplotlib.pyplot 导引
matplotlib.pyplot 是采用 python 语言和使用数值数学库 numpy 数组数据的绘图库.其主要目标是用于数据的可视化显示. 输出图形组成 matplotlib.pyplot 模块 ...
- c# webservice中访问http和https的wsdl,生成的配置节点的不同之处
http: https:
- 巧用花生壳将局域网内的FTP和www服务器发布到互联网
一.目的:用生壳发布FTP和mail服务器到互连网. 二.网络环境:(出租房多家共用路由器上网,ADSL的1Mbps带宽,动态PPPOE拨号,帐号和密码存储在soho路由器中,路由器自动联机上网,并为 ...
- [翻译] MMMaterialDesignSpinner
MMMaterialDesignSpinner Usage To run the example project, clone the repo, and run pod install from t ...
- Java 集合框架(常用数据结构)
早在Java 2中之前,Java就提供了特设类.比如:向量(Vector).栈(Stack).字典(Dictionary).哈希表(Hashtable)这些类(数据结构)用来存储和操作对象组.虽然这些 ...
- 利用Fiddler2和Proxifier分析你用的中国菜刀是否带有后门
为了避免自己辛辛苦苦拿下的站点被一些拿来主义者不费吹灰之力就据为己有,下面来教大家如何检测菜刀有没有留后门. 对于有没有后门这个问题,大牛们会说抓包看一下就行了,那如何抓包呢?有很多软件可以,这里使用 ...
- Java对文件的读取方式以及它们的优缺点
Java常用的对文件的读取方式基本包括: BufferedReader -> readLine(): 按行读取文件,直到读取内容==null FileInputStream -> read ...