Design Add And Search Words Data Structure
medium
Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the WordDictionary class: 1. WordDictionary() Initializes the object. 2. void addWord(word) Adds word to the data structure, it can be matched later. 3. boolean search(word) Returns true if there is any string in the data structure that matches word or false otherwise. word may contain dots '.' where dots can be matched with any letter.
Constraints
1. 1 <= word.length <= 500 2. word in addWord consists lower-case English letters. 3. word in search consist of '.' or lower-case English letters.
Format
Input
Input is managed for you
Output
Output is managed for you
Example
Sample Input
addWord bad
addWord dad
addWord mad
search pad
search bad
search .ad
search b..
Sample Output
false
true
true
true