blob: 5c5e0f4afe8a47fa222c1ba908c9809b9cbfd7b8 (
plain)
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
|
#include "leetcode.h"
class WordDictionary {
public:
WordDictionary() {}
void addWord(string word) { words[word.size()].push_back(word); }
bool search(string word) {
for (auto s : words[word.size()])
if (isEqual(s, word))
return true;
return false;
}
private:
unordered_map<int, vector<string>> words;
bool isEqual(string a, string b) {
for (int i = 0; i < a.size(); i++) {
if (b[i] == '.')
continue;
if (a[i] != b[i])
return false;
}
return true;
}
};
int main() {
WordDictionary *obj = new WordDictionary();
obj->addWord("WordDictionary");
bool param_2 = obj->search("WordDictionary");
if (param_2)
cout << "found";
else
cout << "not found";
}
|