← 返回 openai 的题目列表Implement a Simple Key-Value Store from Scratch
类型:online_judge
Implement a simple in-memory key-value store from scratch.
Requirements
Support operations:
PUT key value: insert/overwrite
GET key: return value; print NULL if missing
DEL key: delete if present
COUNT: print number of keys currently stored
Input (stdin)
First line: integer Q
Next Q lines: one operation per line
key and value are whitespace-free strings
Output (stdout)
Print one line per GET
Print one line per COUNT
Constraints
1 <= Q <= 2*10^5
key, value length 1..128
Aim for overall ~O(Q) time
Example
Input:
8
PUT a 1
PUT b 2
GET a
DEL a
GET a
COUNT
PUT c 3
COUNT
Output:
1
NULL
1
2
Example
Input
8
PUT a 1
PUT b 2
GET a
DEL a
GET a
COUNT
PUT c 3
COUNT
Output
1
NULL
1
2