Description
Design a data structure that supports adding new words and finding if a string matches any previously added string. '.' can match any letter. Return true or false.
Examples
Input:
addWord("bad"), search("b.d")Output:
trueExplanation:
After adding 'bad', searching 'b.d' returns true because '.' is a wildcard matching any character, here 'a'.
Input:
input = ["bad","dad","mad"], arg2 = "pad"Output:
falseExplanation:
The target value does not exist in the given data structure.
Input:
input = ["bad","dad","mad"], arg2 = "b.d"Output:
trueExplanation:
Pattern 'b.d' matches 'bad' where '.' stands for 'a'.
Input:
input = ["bad","dad","mad"], arg2 = ".ad"Output:
trueExplanation:
Pattern '.ad' matches all three words ('bad', 'dad', 'mad') since '.' can be 'b', 'd', or 'm'.
Constraints
- •
1 ≤ word.length ≤ 25 - •
word consists of lowercase English letters. - •
search word may contain '.'.