Skip to content

Commit

Permalink
GOLANG: improve memory usage in 0217-contain-duplicate.go
Browse files Browse the repository at this point in the history
  • Loading branch information
burtsdenis committed Jul 26, 2023
1 parent eed040d commit 5a0efc7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions go/0217-contains-duplicate.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
func containsDuplicate(nums []int) bool {
nums_map := map[int]int{}
for _, n := range nums {
if _, ok := nums_map[n]; !ok {
nums_map[n] = 1
} else {
if len(nums) <= 1 {
return false
}

xm := make(map[int]struct{})

for _, v := range nums {
if _, ok := xm[v]; ok {
return true
}

xm[v] = struct{}{}
}
return false

}
return false
}

0 comments on commit 5a0efc7

Please sign in to comment.