Two Solutions in Python 3 (Trie and DFS) (Set) (beats ~96%)
Using a Dictionary of Sets: (beats ~96%)\n\nclass WordDictionary:\n\n    def __init__(self):\n        self.words = collections.defaultdict(set)\n        \n    d
_Using a Dictionary of Sets:_ (beats ~96%)\n```\nclass WordDictionary:\n\n    def __init__(self):\n        self.words = collections.defaultdict(set)\n        \n    def addWord(self, word: str) -> None:\n    \tself.words[len(word)].add(word)\n        \n    def search(self, word: str) -> bool:\n    \tfor w in self.words[len(word)]:\n    \t\tfor i, c in enumerate(word):\n    \t\t\tif c not in [\'.\',w[i]]: break\n    \t\telse: return True\n    \treturn False\n\t\t\n\t\t\n```\t\t\n_Using Trie and DFS:_\n```\nclass WordDictionary:\n\n    def __init__(self):\n        self.root = {}\n        \n    def addWord(self, word: str) -> None:\n        node = self.root\n        for c in word:\n            if c not in node: node[c] = {}\n            node = node[c]\n        node[\'*\'] = False\n        \n    def search(self, w: str) -> bool:\n    \tdef dfs(node, i):\n    \t\tif node == False: return False\n    \t\tif i == L: return \'*\' in node\n    \t\tif w[i] != \'.\':\n    \t\t\tif w[i] not in node: return False\n    \t\t\treturn dfs(node[w[i]],i+1)\n    \t\tfor j in node.values():\n    \t\t\tif dfs(j,i+1): return True\n    \t\treturn False\n    \tnode, L = self.root, len(w)\n    \treturn dfs(node,0)\n\t\t\n\t\t\n- Junaid Mansuri\n(LeetCode ID)@hotmail.com
['Depth-First Search', 'Trie', 'Ordered Set', 'Python', 'Python3']