← 返回 snowflake 的题目列表CRUD Operations for Key-Value Store with Advanced Search
类型:online_judge
Implement a Key-Value store supporting basic CRUD operations with advanced key searching capabilities. The system should support the following operations:
get(key): Retrieve the value associated with the key.
set(key, value): Set the key to be associated with the value.
update(key, value): Update the value associated with the key to the new value.
delete(key): Remove the key-value pair from the store.
prefixSearch(prefix): Return all values of keys starting with the prefix.
containSearch(substring): Return values of keys containing the substring or null if the key does not exist.
Please implement these operations and provide relevant test cases.
Example
set("abc", 1)
set("abcd", 2)
prefixSearch("ab") // returns [1, 2]
containSearch("ab") // returns null
containSearch("abc") // returns 1
Constraints
The number of keys and values ranges from [1, 10^5].
The length of the string key ranges from [1, 100].
The time complexity of any operation is O(N), where N is the size of the key set.
Example
Input
set abc 1
set abcd 2
prefixSearch ab
containSearch ab
containSearch abc