Skip to content

Commit 1641d25

Browse files
committed
upd
1 parent 6e28425 commit 1641d25

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Diff for: copypasta/trie.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package copypasta
22

3+
import "runtime/debug"
4+
35
/* 前缀树/字典树/单词查找树
46
适用于多串前缀/后缀匹配
57
另类解读:如果将字符串长度视作定值 L 的话,trie 树是一种 O(nL) 排序,O(L) 查询的数据结构
@@ -9,9 +11,6 @@ https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieST.java.html
911
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TrieSET.java.html
1012
https://algs4.cs.princeton.edu/code/edu/princeton/cs/algs4/TST.java.html
1113
12-
注:由于用的是指针写法,必要时禁止 GC,能加速不少
13-
func init() { debug.SetGCPercent(-1) }
14-
1514
模板题 LC208 https://leetcode.cn/problems/implement-trie-prefix-tree/
1615
最长匹配后缀 https://leetcode.cn/problems/longest-common-suffix-queries/
1716
前后缀同时匹配 LC745 https://leetcode.cn/problems/prefix-and-suffix-search/
@@ -29,6 +28,10 @@ https://codeforces.com/problemset/problem/557/E 2300
2928
https://atcoder.jp/contests/abc273/tasks/abc273_e 深刻理解
3029
https://atcoder.jp/contests/abc353/tasks/abc353_e
3130
*/
31+
32+
// 指针写法关闭 GC 可以得到明显加速
33+
func init() { debug.SetGCPercent(-1) }
34+
3235
type trieNode struct {
3336
son [26]*trieNode
3437
cnt int // trieNode 对应的完整字符串的个数

0 commit comments

Comments
 (0)