TRIE + DEPTH FIRST SEARCH || BEATS 50% || JAVA || EASY CODE
Code\n\nclass TrieNode {\n    Map<Character, TrieNode> children;\n    boolean isEnd;\n    TrieNode() {\n        children = new HashMap<>();\n        isEnd = fal
# Code\n```\nclass TrieNode {\n    Map<Character, TrieNode> children;\n    boolean isEnd;\n    TrieNode() {\n        children = new HashMap<>();\n        isEnd = false;\n    }\n}\n\nclass Trie {\n    private final TrieNode root = new TrieNode();\n    Trie(){}\n    \n    public void insert(String str) {\n        TrieNode current = root;\n        for (Character c: str.toCharArray()) {\n            TrieNode child = current.children.get(c);\n            if(child == null) {\n                child = new TrieNode();\n                current.children.put(c, child);\n            }\n            current = child;\n        }\n        current.isEnd = true;\n    }\n    \n    public boolean search(String str) {\n        return dfs(root, 0, str, 0);\n    }\n    \n    private  boolean dfs(TrieNode node, int index, String str, int changed) {\n        if(index == str.length() && node.isEnd && changed == 1) return true;\n        if(changed == 2 || index >= str.length()) return false;\n        for (Map.Entry<Character, TrieNode> child: node.children.entrySet()) {\n            if(dfs(child.getValue(), index+1, str, child.getKey() == str.charAt(index) ? changed : changed + 1))\n                return true;\n        }\n        return false;\n    }\n}\n\n\nclass MagicDictionary {\n    private final Trie trie = new Trie();\n    public MagicDictionary() {\n\n    }\n\n    public void buildDict(String[] dictionary) {\n        for (String word: dictionary)\n            trie.insert(word);\n    }\n\n    public boolean search(String searchWord) {\n        return trie.search(searchWord);\n    }\n}\n```
['String', 'Depth-First Search', 'Design', 'Trie', 'Java']