#208 - Implement Trie (Prefix Tree)
Implement a trie with insert, search, and startsWith methods.
insert(word)– inserts the stringwordinto the trie.search(word)– returnstrueif the exact stringwordis in the trie.startsWith(prefix)– returnstrueif any previously inserted string has the prefixprefix.
| Input | Output |
|---|---|
Operations | Output |
insert("apple"), search("apple"), search("app"), startsWith("app"), insert("app"), search("app") | [null, true, false, true, null, true] |