Design Add and Search Words Data Structure

Medium

Description

Design a data structure that supports adding new words and finding if a string matches any previously added string. '.' can match any letter.

Examples

Input:addWord("bad"), search("b.d")
Output:true
Explanation:

'.' matches 'a'.

Input:input = ["bad","dad","mad"], arg2 = "pad"
Output:false
Explanation:

The target value does not exist in the given data structure.

Input:input = ["bad","dad","mad"], arg2 = "b.d"
Output:true
Explanation:

The target value exists in the given data structure.

Input:input = ["bad","dad","mad"], arg2 = ".ad"
Output:true
Explanation:

The target value exists in the given data structure.

Constraints

  • 1 ≤ word.length ≤ 25
  • word consists of lowercase English letters.
  • search word may contain '.'.

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!