Java || HashMap || buildDict - O(dictionary.length*dictionary[i].length) || search - O(word.length)
class MagicDictionary {\n\n    HashMap map;\n\n\t// O(1)\n\tpublic MagicDictionary() {\n\t\tmap = new HashMap();\n\t}\n\n\t\t// O(dictionary.length * dictionary
class MagicDictionary {\n\n    HashMap<String, Integer> map;\n\n\t// O(1)\n\tpublic MagicDictionary() {\n\t\tmap = new HashMap<String, Integer>();\n\t}\n\n\t\t// O(dictionary.length * dictionary[i].length)\n\t\tpublic void buildDict(String[] dictionary) {\n\t\t\tfor (String word : dictionary) {\n\t\t\t\tchar[] str = word.toCharArray();\n\t\t\t\tfor (int i = 0; i < str.length; i++) {\n\t\t\t\t\tchar temp = str[i];\n\t\t\t\t\tstr[i] = \'*\';\n\t\t\t\t\tString key = String.valueOf(str);\n\t\t\t\t\tmap.put(key, map.getOrDefault(key, 0) + 1);\n\t\t\t\t\tstr[i] = temp;\n\t\t\t\t}\n\t\t\t\tmap.put(word, 1);\n\t\t\t}\n\t\t}\n\n\t\t// O(searchWord.length)\n\t\tpublic boolean search(String searchWord) {\n\t\t\tchar[] word = searchWord.toCharArray();\n\t\t\tfor (int i = 0; i < word.length; i++) {\n\t\t\t\tchar temp = word[i];\n\t\t\t\tword[i] = \'*\';\n\t\t\t\tString key = String.valueOf(word);\n\t\t\t\tint count = map.getOrDefault(key, 0);\n\t\t\t\tif ((count >= 2) || (count == 1 && !map.containsKey(searchWord)))\n\t\t\t\t\treturn true;\n\t\t\t\tword[i] = temp;\n\t\t\t}\n\t\t\treturn false;\n\t\t}\n}\n\n
[]