← 返回 linkedin 的题目列表Design a HashMap
类型:online_judge
Design and implement a HashMap supporting the following operations:
put(key, value): Insert a (key, value) pair into the HashMap. Update the value if the key already exists.
get(key): Return the value to which the specified key is mapped, or -1 if the map contains no mapping for the key.
remove(key): Remove the mapping for the value key if the map contains the mapping for the key.
Constraints:
0 <= key, value <= 10^6
Total number of calls for put, get, and remove methods will be at most 10,000
Input:
put(1, 1)
put(2, 2)
get(1)
get(3)
put(2, 1)
get(2)
remove(2)
get(2)
Output: 1 -1 1 -1
Example
Input
put(1, 1)
put(2, 2)
get(1)
get(3)