[Java] | Trie |
\nclass MagicDictionary {\n\n    private class Node {\n        Node[] links;\n        boolean isEnd;\n        Node() {\n            links = new Node[26];\n     
```\nclass MagicDictionary {\n\n    private class Node {\n        Node[] links;\n        boolean isEnd;\n        Node() {\n            links = new Node[26];\n            isEnd = false;\n        }\n    }\n    \n    private Node root;\n    public MagicDictionary() {\n        root = new Node();\n    }\n    \n    public void buildDict(String[] dictionary) {\n        for (String str : dictionary) {\n            insert(str);\n        }\n    }\n    \n    public boolean search(String searchWord) {\n        return searchUtil(root, searchWord, 0, false);\n    }\n    \n    private void insert(String str) {\n        Node curr = root;\n        for (char c : str.toCharArray()) {\n            int ascii = c - \'a\';\n            if (curr.links[ascii] == null) \n                curr.links[ascii] = new Node();\n            curr = curr.links[ascii];\n        }\n        curr.isEnd = true;\n    }\n    \n    private boolean searchUtil(Node curr, String str, int i, boolean flag) {\n        if (i == str.length()) \n            return (curr.isEnd && i == str.length() && flag);\n        \n        boolean ans = false;\n        int ascii = str.charAt(i) - \'a\';\n        if (!flag) {\n            for (int ii = 0; ii < 26; ii++) {\n                if (ii == ascii || curr.links[ii] == null)\n                    continue;\n                if (searchUtil(curr.links[ii], str, i + 1, true)) return true;\n            }\n        }\n        if (curr.links[ascii] != null && searchUtil(curr.links[ascii], str, i + 1, flag))\n            return true;\n        return false;\n    }\n}\n```
['Trie', 'Java']