Hash Table
Implement a hash table with the following methods:
HashTable()constructs a new instance of a hash tableput(int key, int val)updates the hash table such thatkeymaps tovalget(int key)returns the value associated withkey. If there is no suchkey, then return-1.remove(int key)removes both thekeyand the value associated with it in the hash table.
This should be implemented without using built-in hash table.
Constraints
n ≤ 100,000wherenis the number of calls toput,getandremove
https://binarysearch.com/problems/Hash-Table
Examples
Example 1
Input
- methods =
['constructor', 'put', 'get', 'remove', 'get'] - arguments =
[[], [1, 10], [1], [1], [1]]
Output
- answer =
[None, None, 10, None, -1]
Leave a comment