-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path211.cpp
More file actions
29 lines (26 loc) · 769 Bytes
/
Copy path211.cpp
File metadata and controls
29 lines (26 loc) · 769 Bytes
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
class WordDictionary {
public:
WordDictionary() {
}
void addWord(string word) {
int n = word.size();
m[n].insert(word);
}
bool search(string word) {
int n = word.size();
if(word.find_first_of('.') != string::npos) {
for(auto e: m[n]) {
int isFind = 1;
for(int i = 0; i < n; ++i) {
if(word[i] != '.' && word[i] != e[i])
isFind = 0;
}
if(isFind == 1)
return true;
}
return false;
} else
return m[n].count(word);
}
map<int, unordered_set<string>> m;
};