← Practice · Trie
Implement Trie (Prefix Tree) Medium
Implement a Trie class with three methods: - insert(word): add the word. - search(word): true if exactly this word was inserted. - startsWith(prefix): true if any inserted word begins with prefix.
Examples
insert("apple"), search("apple") -> true, search("app") -> false, startsWith("app") -> true, insert("app"), search("app") -> true.
Define a class named Trie in JavaScript.
00:00▶ Visualize
JavaScript · Tab indents · Ctrl/⌘+Enter runs the tests