classTrie{private:
vector<Trie*> next;bool isEnd;public:/** Initialize your data structure here. */Trie():next(26),isEnd(false){}/** Inserts a word into the trie. */voidinsert(string word){
Trie* cur =this;for(char& c : word){if(!cur->next[c -'a']) cur->next[c -'a']=newTrie();
cur = cur->next[c -'a'];}
cur->isEnd =true;}/** Returns if the word is in the trie. */boolsearch(string word){
Trie* cur =this;for(char& c : word){if(!cur->next[c -'a'])returnfalse;
cur = cur->next[c -'a'];}return cur->isEnd;}/** Returns if there is any word in the trie that starts with the given prefix. */boolstartsWith(string prefix){
Trie* cur =this;for(char& c : prefix){if(!cur->next[c-'a'])returnfalse;
cur = cur->next[c -'a'];}returntrue;}};