473. Add and Search Word
Design a data structure that supports the following two operations: addWord(word)
and search(word)
search(word)
can search a literal word or a regular expression string containing only letters a-z
or .
.
A .
means it can represent any one letter.
Notice
You may assume that all words are consist of lowercase letters a-z.
Example1234567addWord("bad")addWord("dad")addWord("mad")search("pad") // return falsesearch("bad") // return truesearch(".ad") // return truesearch("b..") // return true
典型的Trie的题目,自己写了一遍,还有可以优化的地方。具体做法可以参考九章的答案。在这里我就把我的写法贴出来
|
|