-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathdesign_hashmap.go
More file actions
36 lines (30 loc) · 853 Bytes
/
Copy pathdesign_hashmap.go
File metadata and controls
36 lines (30 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package problem706
type MyHashMap struct {
data map[int]int
}
/** Initialize your data structure here. */
func Constructor() MyHashMap {
return MyHashMap{make(map[int]int, 0)}
}
/** value will always be non-negative. */
func (this *MyHashMap) Put(key int, value int) {
this.data[key] = value
}
/** Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key */
func (this *MyHashMap) Get(key int) int {
if v, ok := this.data[key]; ok {
return v
}
return -1
}
/** Removes the mapping of the specified value key if this map contains a mapping for the key */
func (this *MyHashMap) Remove(key int) {
delete(this.data, key)
}
/**
* Your MyHashMap object will be instantiated and called as such:
* obj := Constructor();
* obj.Put(key,value);
* param_2 := obj.Get(key);
* obj.Remove(key);
*/