mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
34 lines
630 B
Go
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);
|
|
*/
|