Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 50110c8

Browse files
add 804.py
1 parent d968e88 commit 50110c8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎py2/804. Unique Morse Code Words.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
class Solution(object):
2+
def uniqueMorseRepresentations(self, words):
3+
"""
4+
:type words: List[str]
5+
:rtype: int
6+
"""
7+
morse_map = {
8+
'a': '.-',
9+
'b': '-...',
10+
'c': '-.-.',
11+
'd': '-..',
12+
'e': '.',
13+
'f': '..-.',
14+
'g': '--.',
15+
'h': '....',
16+
'i': '..',
17+
'j': '.---',
18+
'k': '-.-',
19+
'l': '.-..',
20+
'm': '--',
21+
'n': '-.',
22+
'o': '---',
23+
'p': '.--.',
24+
'q': '--.-',
25+
'r': '.-.',
26+
's': '...',
27+
't': '-',
28+
'u': '..-',
29+
'v': '...-',
30+
'w': '.--',
31+
'x': '-..-',
32+
'y': '-.--',
33+
'z': '--..'
34+
}
35+
morse_words = []
36+
for word in words:
37+
morse_words.append("".join([morse_map[i] for i in word]))
38+
return len(set(morse_words))
39+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /