Design a data structure that supports adding words and searching with wildcards.
The WordDictionary
class should support:
addWord(word)
: Adds a word to the dictionarysearch(word)
: Returns true if any stored word matches the pattern
Constraints:
Examples:
const dict = new WordDictionary();
dict.addWord("day");
dict.addWord("bay");
dict.addWord("may");
dict.search("say"); // returns false
dict.search("day"); // returns true
dict.search(".ay"); // returns true (matches day, bay, may)
dict.search("b.."); // returns true (matches bay)