- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo804.java
23 lines (21 loc) · 680 Bytes
/
No804.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packageAlgorithm.leetcode.String;
importjava.util.HashSet;
/**
*
* Created by tujietg on Nov 6, 2019
*/
publicclassNo804 {
publicintuniqueMorseRepresentations(String[] words) {
String[] strArray = { ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..",
"--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." };
HashSet<String> set = newHashSet<String>();
for (Stringitem : words) {
StringBuildersb = newStringBuilder();
for (inti = 0; i < item.length(); i++) {
sb.append(strArray[item.charAt(i) - 'a']);
}
set.add(sb.toString());
}
returnset.size();
}
}