Design Add And Search Words Data Structure
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.
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.
Input is managed for you
Output is managed for you
addWord bad addWord dad addWord mad search pad search bad search .ad search b..
false true true true