Implement Trie (Prefix Tree)

 

208. Implement Trie (Prefix Tree)

Solutions

Store words in dictionary whose key is the first character of words, and value is a list of words.

startsWith() requires the first several characters to be known, we can use this information to narrow down the search space. Similar to 211. Add and Search Word - Data structure design