Recursive implementation, ifword[i]is wildcard ‘.’, then start from all child nodes of the current Trie node, searchword.substr(i+1, n-i-1), and whenword[i]=='.'andi==n-1when, at this point it is the last node, the last node is a wildcard, so we only need to check whether the current node’s children haveis_end==trueof
/** * Your WordDictionary object will be instantiated and called as such: * WordDictionary* obj = new WordDictionary(); * obj->addWord(word); * bool param_2 = obj->search(word); */