字典树都是跟的这个博客学的→:https://blog.csdn.net/qq_38891827/article/details/80532462

这些题目也都是他里面的题目,就是把题目按难度排了个序 + 自己整理了下思路(代码也差不多

主要是为了记录一下 忘了的话以后可以翻翻看hhh

模板

const int maxn = 1e5 + 10;
int Next[maxn][26];
bool flag[maxn];
int tol;

void Insert(char *s) {
    int len = strlen(s);
    int root = 0;
    for (int i = 0; i < len; i++) {
        int id = s[i] - 'a';
        if (!Next[root][id]) tree[root][id] = ++tot;
        root = Next[root][id];
    }
    flag[root] = true;
}

bool Find(char *s) {
    int len = strlen(s);
    int root = 0;
    for (int i = 0; i < len; i++) {
        int id = s[i] - 'a';
        if (!Next[root][id]) return false;
        root = Next[root][id];
    }
    return true;
}
View Code

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-06-14
  • 2021-07-14
猜你喜欢
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-03-02
  • 2021-09-05
相关资源
相似解决方案