LeetCode 211 Design Add and Search Words - Problem Statement

The problem

Design a data structure that supports adding words and searching with wildcards.

addWord(word): Add a word to the data structure.

search(word): Return true if any word matches. A . can match any single letter.

With addWord("bad"), addWord("dad"), addWord("mad"):

  • search("pad") returns false (no match).
  • search("bad") returns true (exact match).
  • search(".ad") returns true (. matches 'b', 'd', or 'm').
  • search("b..") returns true (. matches 'a' then 'd').

Constraints: Words contain only lowercase letters. Patterns contain letters and ..