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 thekeyalready exists in the map, update the correspondingvalue.int get(int key)returns thevalueto which the specifiedkeyis mapped, or-1if this map contains no mapping for thekey.void remove(key)removes thekeyand its correspondingvalueif the map contains the mapping for thekey.
Example 1:
1 | Input |
Constraints:
0 <= key, value <= 10^6- At most
10^4calls will be made toput,get, andremove.
Hints/Notes
- 2025/03/20 Q3
- hash and vector
- Leetcode solution
Solution
Language: C++
1 | class MyHashMap { |