//leetcode208classTrie{private:
vector<Trie *> children;bool isEnd;
Trie *searchprefix(string word){
Trie *node =this;for(char ch : word){int c = ch -'a';if(!node->children[c])returnnullptr;
node = node->children[c];}return node;}public:/** Initialize your data structure here. */Trie():children(26),isEnd(false){};/** Inserts a word into the trie. */voidinsert(string word){
Trie *node =this;for(char ch : word){int c = ch -'a';if(!node->children[c])
node->children[c]=newTrie();
node = node->children[c];}
node->isEnd =true;return;}/** Returns if the word is in the trie. */boolsearch(string word){
Trie *node =searchprefix(word);if(node ==nullptr)returnfalse;return node->isEnd;}/** Returns if there is any word in the trie that starts with the given prefix. */boolstartsWith(string prefix){
Trie *node =searchprefix(prefix);if(node ==nullptr|| node->children.size()==0)returnfalse;returntrue;}};/**
* 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);
*/