Clean Java Code with Trie
\nclass MagicDictionary {\n    class Trie{\n        boolean isEnd;\n        Map<Character, Trie> children;\n        Trie(){\n            children = new HashMap(
```\nclass MagicDictionary {\n    class Trie{\n        boolean isEnd;\n        Map<Character, Trie> children;\n        Trie(){\n            children = new HashMap();\n        }\n    }\n    Trie root;\n    \n    public MagicDictionary() {\n        root = new Trie();\n    }\n    \n    public void buildDict(String[] dict) {\n        for(String s : dict){\n            Trie curr = root;\n            for(char c : s.toCharArray()){\n                if(!curr.children.containsKey(c)){\n                    curr.children.put(c, new Trie());\n                }\n                curr = curr.children.get(c);\n            }\n            curr.isEnd = true;\n        }\n    }\n    \n    public boolean search(String word) {\n        return search(word, 0, root, false);\n    }\n    public boolean search(String word, int i, Trie node, boolean flag){\n        if(i < word.length()){\n            if(node.children.containsKey(word.charAt(i))){\n                if(search(word, i+1, node.children.get(word.charAt(i)), flag)){\n                    return true;\n                }\n            }\n            if(!flag){\n                for(char c: node.children.keySet()){\n                    if(c!= word.charAt(i) && search(word, i+1, node.children.get(c), true)) return true;\n                }\n            }\n            return false;\n        }\n        return flag && node.isEnd;\n    }\n}\n```
[]