-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution804.go
54 lines (52 loc) · 850 Bytes
/
solution804.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package solution804
// ============================================================================
// 804. Unique Morse Code Words
// URL: https://leetcode.com/problems/unique-morse-code-words/
// ============================================================================
func uniqueMorseRepresentations(words []string) int {
sl := []string{
".-",
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..",
}
m := make(map[string]int)
output := ""
for _, word := range words {
output = ""
for _, ch := range word {
ch := byte(ch) - 97
output += sl[ch]
}
_,
ok := m[output]
if ok {
m[output]++
} else {
m[output] = 1
}
}
return len(m)
}