Java | implementing trie
\nclass WordDictionary {\n\n    class Trie{\n        Trie[] letters;\n        boolean end;\n        Trie(){\n            letters = new Trie[26];\n            en
```\nclass WordDictionary {\n\n    class Trie{\n        Trie[] letters;\n        boolean end;\n        Trie(){\n            letters = new Trie[26];\n            end = false;\n        }\n    }\n    Trie dict;\n    public WordDictionary() {\n        this.dict = new Trie();\n    }\n    \n    public void addWord(String word) {\n        Trie ptr = this.dict;\n        for(char c : word.toCharArray()){\n            if(ptr.letters[c - \'a\'] == null)\n                ptr.letters[c - \'a\'] = new Trie();\n            ptr = ptr.letters[c - \'a\'];\n        }\n        ptr.end = true; \n    }\n    \n    public boolean search(Trie ptr, String word, int index){\n        if(index >= word.length()) return ptr.end;\n        char c = word.charAt(index);\n\n        if(c == \'.\'){\n            for(Trie t : ptr.letters){\n                if(t != null && search(t, word, index + 1))\n                    return true;\n            }\n            return false;\n        }\n        if(ptr == null || ptr.letters[c - \'a\'] == null) return false;\n        \n        return search(ptr.letters[c - \'a\'], word, index + 1);\n    }\n    public boolean search(String word) {\n        return search(this.dict, word, 0);\n    }\n}\n```
[]