Files
LeetCode-Go/leetcode/0705.Design-HashSet/705. Design HashSet.go
2020-08-07 17:06:53 +08:00

34 lines
630 B
Go

package leetcode
type MyHashSet struct {
data []bool
}
/** Initialize your data structure here. */
func Constructor705() 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
}
/** Returns true if this set contains the specified element */
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);
*/