使用数组进行内部实现
class Trie {
public:
/** Initialize your data structure here. */
int cnt=0;
int nex[100005][26];
bool exist[100005];
Trie() {
cnt = 0;
memset(nex, 0,sizeof(nex));
memset(exist, 0,sizeof(exist));
}
/** Inserts a word into the trie. */
void insert(string word) {
int p =0;
for(int i=0;i<word.size();i++){
if(!nex[p][word[i]-'a']) nex[p][word[i]-'a']=++cnt;
p=nex[p][word[i]-'a'];
}
exist[p] = true;
}
/** Returns if the word is in the trie. */
bool search(string word) {
int p = 0;
for(int i=0;i<word.size();i++){
if(!nex[p][word[i]-'a']) return false;
p = nex[p][word[i]-'a'];
}
return exist[p];
}
/** Returns if there is any word in the