[C++] Easy solution using trie
\nstruct T{\n    bool end=false;\n    T* c[26];\n    T(){\n        end=false;\n        memset(c, NULL, sizeof(c));\n    }\n};\nclass MagicDictionary {\npublic:\
```\nstruct T{\n    bool end=false;\n    T* c[26];\n    T(){\n        end=false;\n        memset(c, NULL, sizeof(c));\n    }\n};\nclass MagicDictionary {\npublic:\n    /** Initialize your data structure here. */\n    T* root;\n    MagicDictionary() {\n        root = new T();\n    }\n    \n    void buildDict(vector<string> dict) {\n        int n=dict.size();\n        // build the trie\n        for(int i=0;i<n;i++)\n        {\n            T* node=root;\n            string word=dict[i];\n            for(int j=0;j<word.size();j++)\n            {\n                if(!node->c[dict[i][j]-\'a\'])\n                    node->c[dict[i][j]-\'a\']=new T();\n                node=node->c[dict[i][j]-\'a\'];\n            }\n            node->end=true;\n        }\n    }\n    \n    bool helper(string word)\n    {\n        T* node=root;\n        int n=word.size();\n        for(int i=0;i<n;i++)\n        {\n            if(!node->c[word[i]-\'a\'])\n                return false;\n            node=node->c[word[i]-\'a\'];\n        }\n        return node->end;\n    }\n    \n    bool search(string sword) {\n        int n=sword.size();\n        string word=sword;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<26;j++)\n            {\n                if(\'a\'+j==sword[i])\n                    continue;\n                word[i]=\'a\'+j;\n                if(helper(word))\n                    return true;\n            }\n            word[i]=sword[i];\n        }\n        return false;\n    }\n};\n```\n\nPlease upvote if it helps you in any way :)
[]