Back to DSA

Design Add and Search Words Data Structure

hard
Acceptance: 40%
TrieDFSDesignString

Create a dictionary data structure that supports two operations: addWord(word) stores a word, and search(pattern) returns true if any stored word matches the pattern. The pattern may contain the wildcard character '.', which can stand for any single letter.

Examples

Example 1:
Input:WordDictionary(), addWord('cat'), addWord('car'), addWord('bar'), search('.ar'), search('c..'), search('b.t')
Output:[null,null,null,null,true,true,false]

Hints

00:00
1234567