Design HashMap LeetCode solution in JavaScript

1
var MyHashMap = function () {
2
this.hashMap = [];
3
};
4

5
/**
6
* @param {number} key
7
* @param {number} value
8
* @return {void}
9
*/
10
MyHashMap.prototype.put = function (key, value) {
11
this.hashMap[key] = [key, value];
12
};
13

14
/**
15
* @param {number} key
16
* @return {number}
17
*/
18
MyHashMap.prototype.get = function (key) {
19
return this.hashMap[key] ? this.hashMap[key][1] : -1;
20
};
21

22
/**
23
* @param {number} key
24
* @return {void}
25
*/
26
MyHashMap.prototype.remove = function (key) {
27
delete this.hashMap[key];
28
};
29

30
/**
31
* Your MyHashMap object will be instantiated and called as such:
32
* var obj = new MyHashMap()
33
* obj.put(key,value)
34
* var param_2 = obj.get(key)
35
* obj.remove(key)
36
*/

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0