Skip to content

Commit a8669da

Browse files
committed
contains-duplicate: refactor
- init map with size. - check exists only in if statement.
1 parent be94a27 commit a8669da

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

contains-duplicate/invidam.go

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

44
for _, num := range nums {
5-
if appeared[num] {
5+
if _, found := appeared[num]; found {
66
return true
77
}
88
appeared[num] = true
99
}
10-
}
10+
11+
return false
12+
}

0 commit comments

Comments
 (0)