采用取模散列+双链表+桶的思想
const buckets int = 233type entry struct {key, val int}type MyHashMap struct {data []list.List}/** Initialize your data structure here. */func Constructor() MyHashMap {return MyHashMap{data: make([]list.List, buckets),}}func (this *MyHashMap) hash(key int) int {return key%buckets}/** value will always be non-negative. */func (this *MyHashMap) Put(key int, value int) {b := this.hash(key)for cur := this.data[b].Front(); cur != nil; cur = cur.Next() {if e := cur.Value.(*entry); e.key == key {e.val = valuereturn}}this.data[b].PushBack(&entry{key: key, val: value})return}/** 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 {b := this.hash(key)for cur := this.data[b].Front(); cur != nil; cur = cur.Next() {if e := cur.Value.(*entry); e.key == key {return e.val}}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) {b := this.hash(key)for cur := this.data[b].Front(); cur != nil; cur = cur.Next() {if e := cur.Value.(*entry); e.key == key {this.data[b].Remove(cur)return}}}/*** Your MyHashMap object will be instantiated and called as such:* obj := Constructor();* obj.Put(key,value);* param_2 := obj.Get(key);* obj.Remove(key);*/
