Simple Iterative Java Solution
In order for a string to exist in a magic dictionary one character in the string must be modified. This means we can compare the incoming string against strings
In order for a string to exist in a magic dictionary one character in the string must be modified. This means we can compare the incoming string against strings in the dictionary and count how many characters do not match between the two. If only one character does not match the word exists in the magic dictionary. \n\nThere are some additional optimizations that we can make like only checking strings that have the same length as the input string and skipping over a word once more than one character has been found to not match.\n\n```\nclass MagicDictionary {\n        private final List<String> words = new ArrayList<>();\n    /** Initialize your data structure here. */\n    public MagicDictionary() {\n    }\n    \n    /** Build a dictionary through a list of words */\n    public void buildDict(String[] dict) {\n        for (String s : dict) {\n            words.add(s);\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        for (String s : words) {\n            // Only check strings that are the same length\n            if (word.length() != s.length()) {\n                continue;\n            }\n            \n            int numWrong = 0;\n            \n            // Compare each letter of each word and count how many letters are off.\n            for (int i = 0; i < word.length(); i++) {\n                char a = word.charAt(i);\n                char b = s.charAt(i);\n                \n                if (a != b) {\n                    numWrong++;\n                }\n                \n                // optimization\n                if (numWrong > 1) {\n                    break;\n                }\n            }\n\n            // If only one letter for each word is off, this is acceptable.\n            if (numWrong == 1) {\n                return true;\n            } \n        }\n        return false;\n    }\n}\n```
[]