Skip to content

Commit 9a83d85

Browse files
committed
Update add-and-search-word-data-structure-design.cpp
1 parent 9a76e25 commit 9a83d85

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

C++/add-and-search-word-data-structure-design.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
class WordDictionary {
55
public:
6-
struct TrieNode{
6+
struct TrieNode {
77
bool isString = false;
88
unordered_map<char, TrieNode *> leaves;
99
};
1010

11-
WordDictionary(){
11+
WordDictionary() {
1212
root_ = new TrieNode();
1313
root_->isString = true;
1414
}
15-
15+
1616
// Adds a word into the data structure.
1717
void addWord(string word) {
1818
auto* p = root_;
@@ -35,9 +35,10 @@ class WordDictionary {
3535
if (s == word.length()) {
3636
return node->isString;
3737
}
38-
if (node->leaves.find(word[s]) != node->leaves.end()){ // Match the char.
38+
// Match the char.
39+
if (node->leaves.find(word[s]) != node->leaves.end()) {
3940
return searchWord(word, node->leaves[word[s]], s + 1);
40-
} else if (word[s] == '.') { // Skip the char.
41+
} else if (word[s] == '.') { // Skip the char.
4142
for (const auto& i : node->leaves) {
4243
if (searchWord(word, i.second, s + 1)) {
4344
return true;
@@ -51,6 +52,7 @@ class WordDictionary {
5152
TrieNode *root_;
5253
};
5354

55+
5456
// Your WordDictionary object will be instantiated and called as such:
5557
// WordDictionary wordDictionary;
5658
// wordDictionary.addWord("word");

0 commit comments

Comments
 (0)