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
12 changes: 5 additions & 7 deletions go/0217-contains-duplicate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
func containsDuplicate(nums []int) bool {
nums_map := map[int]int{}
nums_map := map[int]bool{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
nums_map := map[int]bool{}
nums_map := map[int]struct{}{}

It may make sense to use the struct{} type here because it doesn’t occupy any memory as opposed to bool.

for _, n := range nums {
if _, ok := nums_map[n]; !ok {
nums_map[n] = 1
} else {
if _, ok := nums_map[n]; ok {
return true
}
}
nums_map[n] = true
}
return false

}
}