208. Implement Trie (Prefix Tree)

Description

Implement a trie with insert, search, and startsWith methods.

Note:

  • You may assume that all inputs are consist of lowercase letters a-z.

  • All inputs are guaranteed to be non-empty strings.

Constraints

Approach

Examples

Input:

["Trie", "insert", "search", "search", "startsWith", "insert", "search"]

[[], ["apple"], ["apple"], ["app"], ["app"], ["app"], ["app"]]

Output:

[null, null, true, false, true, null, true]

Solutions

Follow up

Last updated

Was this helpful?