deno.land / x / masx200_leetcode_test@10.6.5 / implement-trie-prefix-tree / PrefixTreeSearchPrefix.ts

PrefixTreeSearchPrefix.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
export function PrefixTreeSearchPrefix<T extends { children: Map<string, T> }>( root: T, prefix: string, { stop, end, each, }: { stop?: (node: T) => boolean; each?: (node: T) => void;
end?: (node: T) => void; } = {},): T | undefined { let node = root;
each?.(root); if (stop?.(root)) return root; for (const ch of prefix) { const next: T = node.children.get(ch) as T; if (!next) { return; }
each?.(next); if (stop?.(next)) return next; node = next; } end?.(node); return node;}
masx200_leetcode_test

Version Info

Tagged at
a year ago