【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 ...
随机推荐
- 微信小程序-movable-view
<view class="page-body"> <view class="page-section"> <view class= ...
- 网络测速 php代码
<?php /*=====http://hi.csdn.net/yinyiniao=====*/ $fp=fopen("cs.txt","w"); for ...
- 应用程序和Activity
Android 应用程序的组成部分 Android应用程序由各个组件组成,并使用Manifest绑定到一起,Manifest描述了每一个组件和它们之间的交互方式,还用于指定权限,硬件,平台以及应用程序 ...
- 三、angularjs上传图片
上传图片需要引入插件ngFileUpload,使用bower安装方法: bower install ng-file-upload --save,安装后需要在命名app的名字js文件中注入,如下所示: ...
- LoadRunner对移动互联网后端服务器压力测试
一.LoadRunner简介 LoadRunner,是惠普公司研发的一款预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题,LoadRunner能够 ...
- Selenium对浏览器的支持
1.火狐浏览器 优点:FireFox Dirver对页面的自动化测试支持得比较好,很直观地模拟页面的操作,对JavaScript的支持也非常完善,基本上页面上做的所有操作FireFox Driver都 ...
- 反射报错java.lang.IllegalArgumentException: wrong number of arguments
class Person{ private String name ; private String sex ; public Person(){ System.out.println("c ...
- win10系统80端口被System (PID=4)占用的解决
今天想用wamp搭建虚拟目录.发现80端口被占用,操作挺麻烦的,所以想要更改. 具体流程如下: 1.“win+R”输入“cmd”,然后输入“netstat -ano | findstr "8 ...
- django1.8 增加注册用户其他字段(用户扩展)
在V1.6及之后版本已经删除get_profile()方法,需要使用userprofile. 1.新建moduel,名为UserProfile: class UserProfile(models.Mo ...
- 定义类/实例(Class)
# -*- coding: UTF-8 -*- class pp(): '''Description''' def __init__(self,name): #初始化函数 self.nam ...