代码拉取完成,页面将自动刷新
package main
import "fmt"
type MyHashMap struct {
InerArr []int
}
/** Initialize your data structure here. */
func Constructor() MyHashMap {
inerArr := make([]int,1000001)
for i := range inerArr {
inerArr[i] = -1
}
return MyHashMap{
InerArr: inerArr,
}
}
/** value will always be non-negative. */
func (this *MyHashMap) Put(key int, value int) {
this.InerArr[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 {
return this.InerArr[key]
}
/** Removes the mapping of the specified value key if this map contains a mapping for the key */
func (this *MyHashMap) Remove(key int) {
this.InerArr[key] = -1
}
func main() {
imap := Constructor()
imap.Put(1,1)
imap.Put(2,2)
imap.Get(1)
imap.Get(3)
imap.Put(2,1)
fmt.Println(imap.Get(2))
imap.Remove(2)
fmt.Println(imap.Get(2))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。