x/masx200_leetcode_test/longest-word-in-dictionary/PrefixTreeSearchPrefixEach.ts
1234567891011121314151617181920212223import { PrefixTree } from "../implement-trie-prefix-tree/PrefixTree.ts";export function PrefixTreeSearchPrefixEach( root: PrefixTree, prefix: string, // each = false,): PrefixTree | undefined { const each = true; let node = root; for (const ch of prefix) { const next = node.children.get(ch); if (!next) { return; } node = next; if (each && !node.isEnd) { return; } } return node;}