C++ Trie Solution avoid memory leak
Many have posted C++/Java Trie solution, for Java, we do not need to consider possible memory leak, but for C++, a lot of people use pointers without releasing 
Many have posted C++/Java Trie solution, for Java, we do not need to consider possible memory leak, but for C++, a lot of people use pointers without releasing them (or not completely release them after terminates), here I post my Trie solution with *shared_ptr*, a smart pointer which guarantees completely memory recycle.\n```\nclass TrieNode {\npublic:\n    vector<shared_ptr<TrieNode>> next;\n    bool is_word;\n    TrieNode() {\n        next = vector<shared_ptr<TrieNode>>(26);\n        is_word = false;\n    }\n};\nclass MagicDictionary {\nprivate:\n    shared_ptr<TrieNode> root;\npublic:\n    /** Initialize your data structure here. */\n    MagicDictionary() {\n        root = make_shared<TrieNode>();\n    }\n\n    /** Build a dictionary through a list of words */\n    void buildDict(vector<string> dict) {\n        for (string& str : dict) {\n            shared_ptr<TrieNode> cur = root;\n            for (char& c : str) {\n                if (cur->next[c - 'a'] == nullptr) {\n                    cur->next[c - 'a'] = make_shared<TrieNode>();\n                }\n                cur = cur->next[c - 'a'];\n            }\n            cur->is_word = true;\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    bool search(string word) {\n        for (int i = 0; i < word.size(); i++) {\n            for (char c = 'a'; c <= 'z'; c++) {\n                if (word[i] == c) continue;\n                char temp = word[i];\n                word[i] = c;\n                if (searchTrie(word)) return true;\n                word[i] = temp;\n            }\n        }\n        return false;\n    }\n\n    bool searchTrie(string& word) {\n        shared_ptr<TrieNode> cur = root;\n        for (char& c : word) {\n            if (cur->next[c - 'a'] == nullptr) return false;\n            cur = cur->next[c - 'a'];\n        }\n        return cur->is_word;\n    }\n};\n```
[]