Link to the problem
The problem is here: https://leetcode-cn.com/problems/implement-trie-prefix-tree/
Trie
A trie (sounds like ‘try’), also called digital tree or prefix tree, is a type of multi-way search tree (多路搜索树).
Trie can be used in tasks like auto-complete or spell-checking.
It is used to store and search strings efficiently. An intuitive design of a trie is like this:

The root node is actually a dummy node. The boolean value of a node is indicating whether that node is a termination or not.
For example, an is a word in the trie while na is not.
Simple Implementation
class Trie {private:struct TrieNode {vector<TrieNode *> child_;bool terminated_;TrieNode() : child_(26, nullptr), terminated_(false) { }};TrieNode root_;public:/** Initialize your data structure here. */Trie() {}/** Inserts a word into the trie. */void insert(string word) {auto node = &root_;for (char c : word) {auto idx = c - 'a';if (!node->child_[idx]) {node->child_[idx] = new TrieNode();}node = node->child_[idx];}node->terminated_ = true;}/** Returns if the word is in the trie. */bool search(string word) {auto node = &root_;for (char c : word) {auto idx = c - 'a';if (!node->child_[idx]) {return false;}node = node->child_[idx];}return node->terminated_;}/** Returns if there is any word in the trie that starts with the given prefix. */bool startsWith(string prefix) {auto node = &root_;for (char c : prefix) {auto idx = c - 'a';if (!node->child_[idx]) {return false;}node = node->child_[idx];}return true;}};/*** Your Trie object will be instantiated and called as such:* Trie* obj = new Trie();* obj->insert(word);* bool param_2 = obj->search(word);* bool param_3 = obj->startsWith(prefix);*/
Possible Improvements
May use map instead of vector to save memory usage.
