706. Design HashMap
Description
Design a HashMap without using any built-in hash table libraries.
Implement the MyHashMap
class:
MyHashMap()
initializes the object with an empty map.void put(int key, int value)
inserts a(key, value)
pair into the HashMap. If thekey
already exists in the map, update the correspondingvalue
.int get(int key)
returns thevalue
to which the specifiedkey
is mapped, or-1
if this map contains no mapping for thekey
.void remove(key)
removes thekey
and its correspondingvalue
if the map contains the mapping for thekey
.
Example 1:
1 | Input |
Constraints:
0 <= key, value <= 10^6
- At most
10^4
calls will be made toput
,get
, andremove
.
Hints/Notes
- 2025/03/20 Q3
- hash and vector
- Leetcode solution
Solution
Language: C++
1 | class MyHashMap { |