← 返回 bytedance 的题目列表Auto-complete System
类型:online_judge
Given a dictionary that contains a set of words, implement an auto-complete system. When the user inputs a prefix string, you must return all words that start with the given prefix. It is recommended to use the Trie (prefix tree) data structure for implementation.
Example:
Input:
words = ["apple", "app", "apricot", "banana", "berry"]
prefix = "ap"
Output:
["apple", "app", "apricot"]
Input:
words = ["dog", "deer", "deal"]
prefix = "de"
Output:
["deer", "deal"]
Constraints:
Word length is between [1, 50]
The total number of words in the dictionary does not exceed 10^5
Prefix length does not exceed 50
Example
Input
words = ['apple', 'app', 'apricot', 'banana', 'berry']
prefix = 'ap'