# LeetCode: Design Hashmap Solution

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}/**2 * Initialize your data structure here.3 */4var MyHashMap = function () {5  this.obj = {}6}7
8/**9 * value will always be non-negative.10 * @param {number} key11 * @param {number} value12 * @return {void}13 */14MyHashMap.prototype.put = function (key, value) {15  this.obj[key] = value16}17
18/**19 * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key20 * @param {number} key21 * @return {number}22 */23MyHashMap.prototype.get = function (key) {24  return this.obj.hasOwnProperty(key) ? this.obj[key] : -125}26
27/**28 * Removes the mapping of the specified value key if this map contains a mapping for the key29 * @param {number} key30 * @return {void}31 */32MyHashMap.prototype.remove = function (key) {33  delete this.obj[key]34}35
36/**37 * Your MyHashMap object will be instantiated and called as such:38 * var obj = new MyHashMap()39 * obj.put(key,value)40 * var param_2 = obj.get(key)41 * obj.remove(key)42 */```

leetcode

hash table

## Next Post

LeetCode: Remove Palindromic Subsequences

Mar 9, 2021

Search Posts