Skip to content

Commit 1eb001d

Browse files
committed
solve problem Unique Morse Code Words
1 parent 12b0e44 commit 1eb001d

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ All solutions will be accepted!
88
|657|[Judge Route Circle](https://leetcode-cn.com/problems/judge-route-circle/description/)|[java/py/js](./algorithms/JudgeRouteCircle)|Easy|
99
|461|[Hamming Distance](https://leetcode-cn.com/problems/hamming-distance/description/)|[java/py/js](./algorithms/HammingDistance)|Easy|
1010
|476|[Number Complement](https://leetcode-cn.com/problems/number-complement/description/)|[java/py/js](./algorithms/NumberComplement)|Easy|
11-
|728|[Self Dividing Numbers](https://leetcode-cn.com/problems/self-dividing-numbers/description/)|[java/py/js](./algorithms/SelfDividingNumbers)|Easy|
11+
|728|[Self Dividing Numbers](https://leetcode-cn.com/problems/self-dividing-numbers/description/)|[java/py/js](./algorithms/SelfDividingNumbers)|Easy|
12+
|804|[Unique Morse Code Words](https://leetcode-cn.com/problems/unique-morse-code-words/description/)|[java/py/js](./algorithms/UniqueMorseCodeWords)|Easy|
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Self Dividing Numbers
2-
This program is easy to solve
2+
This problem is easy to solve
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Unique Morse Code Words
2+
This problem is easy to solve
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int uniqueMorseRepresentations(String[] words) {
3+
String[] checkList = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
4+
Set<String> translatedSet = new HashSet<String>();
5+
for (String word : words) {
6+
String translatedStr = "";
7+
for (char c : word.toCharArray()) {
8+
translatedStr += checkList[(int) c - 97];
9+
}
10+
translatedSet.add(translatedStr);
11+
}
12+
return translatedSet.size();
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {string[]} words
3+
* @return {number}
4+
*/
5+
var uniqueMorseRepresentations = function(words) {
6+
let checkList = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
7+
let translatedSet = new Set()
8+
words.forEach(word => {
9+
let translatedStr = ''
10+
word.split('').forEach(char => {
11+
translatedStr += checkList[char.charCodeAt() - 'a'.charCodeAt()]
12+
})
13+
translatedSet.add(translatedStr)
14+
})
15+
return translatedSet.size
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution(object):
2+
def uniqueMorseRepresentations(self, words):
3+
"""
4+
:type words: List[str]
5+
:rtype: int
6+
"""
7+
check_list = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
8+
translated_set = set()
9+
for word in words:
10+
translated_str = ''
11+
for char in word:
12+
translated_str += check_list[ord(char) - ord('a')]
13+
translated_set.add(translated_str)
14+
return len(translated_set)

0 commit comments

Comments
 (0)