-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique-morse-code-words.cpp
48 lines (45 loc) · 1.34 KB
/
unique-morse-code-words.cpp
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
class Solution {
public:
void init(vector<string>& Morse){
Morse.push_back(".-");
Morse.push_back("-...");
Morse.push_back("-.-.");
Morse.push_back("-..");
Morse.push_back(".");
Morse.push_back("..-.");
Morse.push_back("--.");
Morse.push_back("....");
Morse.push_back("..");
Morse.push_back(".---");
Morse.push_back("-.-");
Morse.push_back(".-..");
Morse.push_back("--");
Morse.push_back("-.");
Morse.push_back("---");
Morse.push_back(".--.");
Morse.push_back("--.-");
Morse.push_back(".-.");
Morse.push_back("...");
Morse.push_back("-");
Morse.push_back("..-");
Morse.push_back("...-");
Morse.push_back(".--");
Morse.push_back("-..-");
Morse.push_back("-.--");
Morse.push_back("--..");
}
int uniqueMorseRepresentations(vector<string>& words) {
vector<string> Morse;
init(Morse);
set<string> Set;
for(int i = 0 ; i < words.size(); i++){
string morse = "";
for(int j = 0; j < words[i].length() ; j++){
morse += Morse[words[i][j] - 'a'];
}
cout << morse << endl;
Set.insert(morse);
}
return Set.size();
}
};