C++ Easy to Understand Trie Solution
\tstruct node {\n\t\t\tint count;\n\t\t\tint ew;\n\t\t\tnode ar[26];\n\t\t};\n\t\tnode getNode() {\n\t\t\tnode n=new node();\n\t\t\tn->ew=0; \n\t\t\tfor(int i=0
\tstruct node {\n\t\t\tint count;\n\t\t\tint ew;\n\t\t\tnode* ar[26];\n\t\t};\n\t\tnode* getNode() {\n\t\t\tnode* n=new node();\n\t\t\tn->ew=0; \n\t\t\tfor(int i=0;i<26;i++) n->ar[i]=NULL;\n\t\t\tn->count=0;\n\t\t\treturn n;\n\t\t}\n\t\tvoid insert(node* root,string s) {\n\t\t\tnode* temp=root;\n\t\t\tfor(int i=0;i<s.size();i++) {\n\t\t\t\tint j=s[i]-\'a\';\n\t\t\t\tif(temp->ar[j]==NULL) temp->ar[j]=getNode();\n\t\t\t\ttemp=temp->ar[j]; temp->count++;\n\t\t\t}\n\t\t\ttemp->ew++;\n\t\t}\n\t\tbool find(node* root,string s) {\n\t\t\tnode* temp=root;\n\t\t\tfor(int i=0;i<s.size();i++) {\n\t\t\t\tint j=s[i]-\'a\';\n\t\t\t\tif(temp->ar[j]==NULL) return false;\n\t\t\t\ttemp=temp->ar[j]; \n\t\t\t}\n\t\t\tif(temp->ew>=1) return true;\n\t\t\treturn false;\n\t\t}\n\t\tnode* root;\n\t\tMagicDictionary() {\n\t\t\troot=getNode();\n\t\t}\n\n\t\tvoid buildDict(vector<string> dictionary) {\n\t\t\tfor(auto s: dictionary) insert(root,s);\n\t\t}\n\n\t\tbool search(string s) {\n\n\t\tfor(int i=0;i<s.size();i++) {\n\t\t\tfor(int j=0;j<26;j++) {\n\t\t\t\tchar c=(char)(j+\'a\');\n\t\t\t\tchar t=s[i];\n\t\t\t\tif(s[i]==c) continue;\n\t\t\t\ts[i]=c;\n\n\t\t\t\tif(find(root,s)) { return true; }\n\t\t\t\ts[i]=t;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}
[]