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.

Input Format

Input is managed for you

Output Format

Output is managed for you

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.

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
addWord bad
addWord dad
addWord mad
search pad
search bad
search .ad
search b..
Output
false
true
true
true
Previous
Maximum Xor Of Two Numbers In An Array
Next
Word Search Ii

Related Questions