trie树(Hash表+节时间耗空间)

#include <iostream>
#include <string>
#include <cstring>
#include <unordered_map>
using namespace std;
struct Trie{
    int exist;
    unordered_map<int, Trie*> child;
    Trie():exist(0){}
};
int insert(Trie *t, const string &str){
    Trie *root = t;
    for(int i = 0; i < str.size(); i++){    
        int place = str[i] - 'a';
        if(root->child.find(place) != root->child.end())    
            root = root->child[place]; 
        else{
            root->child[place] = new Trie();
            root = root->child[place];
        }
        if(i == str.size() - 1){
            root->exist++;
            return root->exist;
        }
    }
}