Skip to content

Commit 733fc96

Browse files
committed
contains-duplicate: refactor function
1 parent 2b171cc commit 733fc96

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

contains-duplicate/invidam.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
func containsDuplicate(nums []int) bool {
2-
appeared := make(map[int]bool, len(nums)/4)
2+
appeared := make(map[int]bool)
33

44
for _, num := range nums {
5-
if _, found := appeared[num]; found {
6-
return true
7-
}
85
appeared[num] = true
96
}
107

11-
return false
12-
}
8+
return len(appeared) != len(nums)
9+
}

0 commit comments

Comments
 (0)