-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsolution.py
26 lines (24 loc) · 963 Bytes
/
solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
82 / 82 test cases passed.
Runtime: 40 ms
Memory Usage: 14.9 MB
"""
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
rec = set()
for word in words:
m_word = ""
for c in word:
m_word += morse[(ord(c) - ord('a'))]
rec.add(m_word)
return len(rec)
"""
82 / 82 test cases passed.
Runtime: 32 ms
Memory Usage: 15.1 MB
"""
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
return len(set("".join(morse[ord(c) - ord('a')] for c in word) for word in words))