706. 设计哈希映射
1/**
2 * Initialize your data structure here.
3 */
4var MyHashMap = function() {
5 // 创建数组
6 let MyHashMap = [];
7};
8
9/**
10 * value will always be non-negative.
11 * @param {number} key
12 * @param {number} value
13 * @return {void}
14 */
15MyHashMap.prototype.put = function(key, value) {
16 this[key] = value;
17};
18
19/**
20 * Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key
21 * @param {number} key
22 * @return {number}
23 */
24MyHashMap.prototype.get = function(key) {
25 return (this[key] === undefined) ? -1 : this[key];
26};
27
28/**
29 * Removes the mapping of the specified value key if this map contains a mapping for the key
30 * @param {number} key
31 * @return {void}
32 */
33MyHashMap.prototype.remove = function(key) {
34 this[key] = -1;
35};
36
37/**
38 * Your MyHashMap object will be instantiated and called as such:
39 * var obj = Object.create(MyHashMap).createNew()
40 * obj.put(key,value)
41 * var param_2 = obj.get(key)
42 * obj.remove(key)
43 */