705. 设计哈希集合

设计哈希集合

解法一: 数组

go
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
type MyHashSet struct {
data []bool
}

func Constructor() MyHashSet {
return MyHashSet{
data: make([]bool, 1000001),
}
}

func (this *MyHashSet) Add(key int) {
this.data[key] = true
}

func (this *MyHashSet) Remove(key int) {
this.data[key] = false
}

func (this *MyHashSet) Contains(key int) bool {
return this.data[key]
}

/**
* Your MyHashSet object will be instantiated and called as such:
* obj := Constructor();
* obj.Add(key);
* obj.Remove(key);
* param_3 := obj.Contains(key);
*/
作者

wuhunyu

发布于

2024-04-14

更新于

2025-01-15

许可协议