Easiest JAVA with Trie, no need to count the number of changes
Below is my accepted java code.\nFirst build a trie tree, and in search(String word) function, we just edit every character from 'a' to 'z' and search the new s
Below is my accepted java code.\nFirst build a trie tree, and in search(String word) function, we just edit every character from 'a' to 'z' and search the new string. \n (This process is like "word ladder")\n\n````\nclass MagicDictionary {\n    class TrieNode {\n        TrieNode[] children = new TrieNode[26];\n        boolean isWord;\n        public TrieNode() {}\n    }\n    TrieNode root;\n    /** Initialize your data structure here. */\n    public MagicDictionary() {\n        root = new TrieNode();\n    }\n    \n    /** Build a dictionary through a list of words */\n    public void buildDict(String[] dict) {\n        for (String s : dict) {\n            TrieNode node = root;\n            for (char c : s.toCharArray()) {\n                if (node.children[c - 'a'] == null) {\n                    node.children[c - 'a'] = new TrieNode();\n                }\n                node = node.children[c - 'a'];\n            }\n            node.isWord = true;\n        }\n    }\n    \n    /** Returns if there is any word in the trie that equals to the given word after modifying exactly one character */\n    public boolean search(String word) {\n        char[] arr = word.toCharArray();\n        for (int i = 0; i < word.length(); i++) {\n            for (char c = 'a'; c <= 'z'; c++) {\n                if (arr[i] == c) {\n                    continue;\n                }\n                char org = arr[i];\n                arr[i] = c;\n                if (helper(new String(arr), root)) {\n                    return true;\n                }\n                arr[i] = org;\n            }\n        }\n        return false;\n    }\n    public boolean helper(String s, TrieNode root) {\n        TrieNode node = root;\n        for (char c : s.toCharArray()) {\n            if (node.children[c - 'a'] == null) {\n                return false;\n            }\n            node = node.children[c - 'a'];\n        }\n        return node.isWord;\n    }\n}\n````
['Trie', 'Java']