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

TrieNodeErase.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { TrieNode } from "./TrieNode.ts";
export function TrieNodeErase(root: TrieNode, word: string) { if (word.length === 0) return; let node = root; for (const ch of word) { const parent = node; const next = node.children.get(ch); if (!next) return; node = next; node.prefixCount--; if (node.prefixCount === 0) { parent.children.delete(ch); return; } } node.wordCount--;}
masx200_leetcode_test

Version Info

Tagged at
a year ago