1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
MyHashMap.go 922 Bytes
一键复制 编辑 原始数据 按行查看 历史
catyMap 提交于 2021-03-30 22:11 +08:00 . 未归类算法题目提交
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))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助