C++, unordered_set
The solution is to use hash table to save the dictionary. For each word to search, generate all possible candidates and verify whether it is in the dictionary.\
The solution is to use hash table to save the dictionary. For each word to search, generate all possible candidates and verify whether it is in the dictionary.\nFor the follow-up question, we should implement a trie rather than use hash table. Trie uses less space and more efficient for a large dictionary. \n```\nclass MagicDictionary {\npublic:\n    /** Initialize your data structure here. */\n    MagicDictionary() {\n        \n    }\n    \n    /** Build a dictionary through a list of words */\n    void buildDict(vector<string> dict) {\n        for (string &s:dict) words.insert(s);\n    }\n    \n    /** Returns if there is any word in the trie that equals to the given word after modifying exactly one character */\n    bool search(string word) {\n          for (int i = 0; i < word.size(); i++) {\n            char c = word[i];\n            for (int j = 0; j < 26; j++) {\n                if (c == j+'a') continue;\n                word[i] = j+'a';\n                if (words.count(word)) return true;\n            }\n            word[i] = c;\n        }\n        return false;\n    }\nprivate:\n    unordered_set<string> words;\n};\n```
[]