Trie simple approach
Intuition\nTrie approach\n\n# Approach\n1. Trie\n2. Recurse to find if there is a difference of one character in the most efficient way\n\n\n\n# Code\n\nclass M
# Intuition\nTrie approach\n\n# Approach\n1. Trie\n2. Recurse to find if there is a difference of one character in the most efficient way\n\n\n\n# Code\n```\nclass MagicDictionary {\n\n   Trie trie=new Trie();\n   static class Trie{\n       Map<Character,Trie> trieMap=new HashMap<Character,Trie>(); \n        boolean eow=false;\n       public String toString(){\n           return trieMap.toString();\n       }\n   }\n\n    public MagicDictionary() {\n        \n    }\n    \n    public void buildDict(String[] dictionary) {\n        for(String word:dictionary){\n            Trie tmpTrie=trie;\n\n            for(char c:word.toCharArray()){\n                tmpTrie.trieMap.putIfAbsent(c,new Trie());\n                tmpTrie=tmpTrie.trieMap.get(c);\n            }   \n            tmpTrie.eow=true;           \n        }\n\n      \n    }\n    \n    public boolean hasOneCharacDiff(String searchWord,int index,int runDiff,Trie trie){\n            if(runDiff>1) return false;\n           \n            if(index>=searchWord.length()){\n                if(runDiff==1 && trie.eow) return true;\n                return false;\n            }\n\n            char c=searchWord.charAt(index);\n            for(char k: trie.trieMap.keySet()){\n                int addition=k==c?0:1;\n                if(hasOneCharacDiff(searchWord,index+1,runDiff+addition,trie.trieMap.get(k)))return true;\n            }\n            \n            return false;\n    }\n\n    public boolean search(String searchWord) {\n        if(hasOneCharacDiff(searchWord,0,0,trie)) return true;\n        return false;\n    }\n\n   \n}\n\n/**\n * Your MagicDictionary object will be instantiated and called as such:\n * MagicDictionary obj = new MagicDictionary();\n * obj.buildDict(dictionary);\n * boolean param_2 = obj.search(searchWord);\n */\n```
['Java']