-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
26 lines (22 loc) · 829 Bytes
/
Copy pathSolution.java
File metadata and controls
26 lines (22 loc) · 829 Bytes
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
import java.util.HashSet;
import java.util.Set;
class Solution
{
private static final String[] MORSE_CODE = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---"
, "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-" +
".--", "--.."};
public int uniqueMorseRepresentations(String[] words)
{
Set<String> transformations = new HashSet<>();
for (String word : words)
{
StringBuilder transformation = new StringBuilder();
for (char chr : word.toLowerCase().toCharArray())
{
transformation.append(MORSE_CODE[chr - 'a']);
}
transformations.add(transformation.toString());
}
return transformations.size();
}
}