首页 > 编程语言 > 详细

LeetCode-804 Unique Morse Code Words Solution (with Java)

时间:2020-03-02 16:56:46      阅读:79      评论:0      收藏:0      [点我收藏+]

1. Description:

技术分享图片

Notes:

技术分享图片

2. Examples:

技术分享图片

3.Solutions:

 1 /**
 2  * Created by sheepcore on 2019-02-24
 3  */
 4 class Solution {
 5     public int uniqueMorseRepresentations(String[] strs) {
 6         char ch;  //current char of eace word
 7         String morse = "";  //morsecode for each word
 8         Set morseSet = new HashSet(); //used for containing morsecodes
 9         final String[] morsecode = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-",
10                                      ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...",  "-", "..-", "...-", 
11                                      ".--", "-..-", "-.--","--.." };
12         int i;
13         for (i = 0; i < strs.length; i++) {
14             for (int j = 0; j < strs[i].length(); j++) {
15                 ch = strs[i].charAt(j);
16                 morse += morsecode[ch - ‘a‘];
17             }
18             morseSet.add(morse);
19             morse = "";
20         }
21         return morseSet.size();
22     }
23 }

 

LeetCode-804 Unique Morse Code Words Solution (with Java)

原文:https://www.cnblogs.com/sheepcore/p/12395976.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!