diff --git a/go/0705-design-hashset.go b/go/0705-design-hashset.go new file mode 100644 index 000000000..4171b61d9 --- /dev/null +++ b/go/0705-design-hashset.go @@ -0,0 +1,28 @@ +type MyHashSet struct { + present []bool +} + +func Constructor() MyHashSet { + return MyHashSet{ + present: make([]bool, 1000001), + } +} + +func (this *MyHashSet) Add(key int) { + if key >= 0 && key < len(this.present) { + this.present[key] = true + } +} + +func (this *MyHashSet) Remove(key int) { + if key >= 0 && key < len(this.present) { + this.present[key] = false + } +} + +func (this *MyHashSet) Contains(key int) bool { + if key < 0 || key >= len(this.present) { + return false + } + return this.present[key] +}