211. Design Add And Search Words Data Structure
Practice Design Add And Search Words Data Structure for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Build a word dictionary:
addWord(word)adds a lowercaseword.search(word)returnstrueif some added word matchesword. Inword, a'.'matches any one letter.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).
Example
["WordDictionary","addWord","addWord","addWord","search","search","search","search"]
[[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
-> [null,null,null,null,false,true,true,true]
Constraints
- 1 <= word.length <= 25
- Added words are lowercase letters; searched words are lowercase letters or
'.' - At most 2 dots in each searched word
- At most 10^4 calls in total