← 返回 snowflake 的题目列表Implement Trie with Non-Standard Alphabet
类型:online_judge
Implement a Trie with a non-standard alphabet. Unlike the traditional alphabet, you need to support more than 26 characters. Implement the following functions:
insert(word: str): Inserts a word into the Trie.
search(word: str) -> bool: Returns if the word is in the Trie.
startsWith(prefix: str) -> bool: Returns if there is any word in the Trie that starts with the given prefix.
Assume the provided alphabet contains unique characters and is passed as a string parameter alphabet. Initially, the Trie is empty.
Test Cases
insert("apple")
search("apple") -> True
search("app") -> False
startsWith("app") -> True
insert("app")
search("app") -> True
Alphabet: alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
Data constraints:
Each word's length does not exceed 100.
There are at most 1000 insert or search operations in each test scenario.
Example
Input
insert apple
search apple
search app
startsWith app
insert app
search app