Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions go/0705-design-hashset.go
Original file line number Diff line number Diff line change
@@ -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]
}