-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorseCode.java
More file actions
38 lines (36 loc) · 1.33 KB
/
MorseCode.java
File metadata and controls
38 lines (36 loc) · 1.33 KB
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
<<<<<<< HEAD
//804. Unique Morse Code Words
class Solution {
public int uniqueMorseRepresentations(String[] words) {
String[] code = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--.."};
Set<String> set = new HashSet<>();
for(String word : words){
String morse = new String();
for(char c : word.toCharArray()){
morse = morse.concat(code[c - 'a']);
}
set.add(morse);
}
return set.size();
}
=======
//804. Unique Morse Code Words
class Solution {
public int uniqueMorseRepresentations(String[] words) {
String[] code = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--","--.."};
Set<String> set = new HashSet<>();
for(String word : words){
String morse = new String();
for(char c : word.toCharArray()){
morse = morse.concat(code[c - 'a']);
}
set.add(morse);
}
return set.size();
}
>>>>>>> be6ce0b427078b1421d5dd74adb2300dc02daeec
}