forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_804.java
25 lines (23 loc) · 942 Bytes
/
_804.java
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
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _804 {
public static class Solution1 {
public int uniqueMorseRepresentations(String[] words) {
String[] morseCodes =
new String[]{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---",
"-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-",
".--", "-..-", "-.--", "--.."};
Set<String> concatenation = new HashSet<>();
StringBuilder sb = new StringBuilder();
for (String word : words) {
sb.setLength(0);
for (char c : word.toCharArray()) {
sb.append(morseCodes[c - 'a']);
}
concatenation.add(sb.toString());
}
return concatenation.size();
}
}
}