-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path804.cpp
More file actions
19 lines (19 loc) · 770 Bytes
/
Copy path804.cpp
File metadata and controls
19 lines (19 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public:
int uniqueMorseRepresentations(vector<string> &words) {
vector<string> morse{".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--",
"--.."};
map<string, int> uni;
for (int i = 0; i < words.size(); ++i) {
string temp;
for (int j = 0; j < words[i].size(); ++j)
temp += morse[words[i][j] - 'a'];
if (uni.find(temp) == uni.end())
uni.insert(map<string, int>::value_type(temp, 1));
else
++uni[temp];
}
return uni.size();
}
};