File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 1
1
package copypasta
2
2
3
+ import "runtime/debug"
4
+
3
5
/* 前缀树/字典树/单词查找树
4
6
适用于多串前缀/后缀匹配
5
7
另类解读:如果将字符串长度视作定值 L 的话,trie 树是一种 O(nL) 排序,O(L) 查询的数据结构
@@ -9,9 +11,6 @@ https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieST.java.html
9
11
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieSET.java.html
10
12
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TST.java.html
11
13
12
- 注:由于用的是指针写法,必要时禁止 GC,能加速不少
13
- func init() { debug.SetGCPercent(-1) }
14
-
15
14
模板题 LC208 https://leetcode.cn/problems/implement-trie-prefix-tree/
16
15
最长匹配后缀 https://leetcode.cn/problems/longest-common-suffix-queries/
17
16
前后缀同时匹配 LC745 https://leetcode.cn/problems/prefix-and-suffix-search/
@@ -29,6 +28,10 @@ https://codeforces.com/problemset/problem/557/E 2300
29
28
https://atcoder.jp/contests/abc273/tasks/abc273_e 深刻理解
30
29
https://atcoder.jp/contests/abc353/tasks/abc353_e
31
30
*/
31
+
32
+ // 指针写法关闭 GC 可以得到明显加速
33
+ func init () { debug .SetGCPercent (- 1 ) }
34
+
32
35
type trieNode struct {
33
36
son [26 ]* trieNode
34
37
cnt int // trieNode 对应的完整字符串的个数
You can’t perform that action at this time.
0 commit comments